Binary Conversion

Here’s a piece of code if you want to convert to binary using C/AL

Int2Bin(InStr : Text[50]) BinStr : Text[50]
WHILE Quotient > 0 DO 
 BEGIN
   i += 1;
   IF i MOD 8 = 1 THEN
   BinStr := PADSTR('', 8, '0') + BinStr; //Insert 8 zeros for each new byte
   Remainder := Quotient MOD 2;
   Quotient := Quotient DIV 2;
   Pos := STRLEN(BinStr) - i + 1 ; //The position in the string where to insert the bit
   BinStr := COPYSTR(BinStr, 1, Pos - 1) + FORMAT(Remainder) + COPYSTR(BinStr, Pos + 1);
 END;
No comments yet.

Kommentera