Mega Code Archive

 
Categories / Delphi / Strings
 

Show values in binary representation

function BinB(b: Byte): string; var s: string; i: word; begin s := ''; for i := 7 downto 0 do if (b and (1 shl i)) > 0 then s := s + '1' else s := s + '0'; BinB := s; end; function BinW(w: Word): string; var s: string; i: word; begin s := ''; for i := 15 downto 0 do if (w and (1 shl i)) > 0 then s := s + '1' else s := s + '0'; BinW := s; end; function BinL(l: Longint): string; var HL: HiLo absolute l; begin BinL := BinW(HL.HiWord) + BinW(HL.LoWord); end;