Bin Operator

Bin makes the runtime system interpret a string variable or the result of a string returning function as binary data. In this case not the Strlen() function is taken for length calculations but the Binlen() function, which returns the actual binary length of the data.

Syntax

Bin = "bin" "(" String | StringFunc ")".

Example

dclfunc
  function Assert(b : boolean) <API_FUNCTION>
  begin
    if b then
      Print("ok");
    else
      Print("failed");
    end
  end Assert;

  function RetString : string
  begin
    RetString := "\h11002233";
  end RetString;

dcltrans
  transaction TMain
  var
    s1, s2, s3 : string;
  begin
    s1 := "\h11002233";      // "\h11002233"
    s2 := "\h550066";        // "\h550066"
    s3 := s1; // "\h11"
    s3 := s1 + "\h770088";   // "\h11770088"
    s3 := "\h770088" + s1;   // "\h77008811"
    s3 := bin(s1);           // "\h11002233"
    s3 := s1 + s2;           // "\h1155"
    s3 := bin(s1) + s2;      // "\h1100223355"
    s3 := s1 + bin(s2);      // "\h11550066"
    s3 := bin(s1) + bin(s2); // "\h11002233550066"
    s3 := RetString();       // "\h11"
    s3 := bin(RetString());  // "\h11002233"

    // comparisons
    // "\h11" = "\h11"
    Assert(s1 = s1);
    // "\h11" = "\h11002233"
    Assert(not (s1 = bin(s1)));
    // "\h11002233" = "\h11002233"
    Assert(s1 + "\h002233" = bin(s1));

  end TMain;