Delphi offers the IntToHex() function to convert integer values to hex string representations but what if you need to convert a number to a binary not a hex? Well, here’s the code for converting byte values to strings:
function IntToBin(btValue: Byte): string;
function Next(btJ: Byte): string;
begin
if btValue and btJ = 0 then
Result := '0'
else
Result := '1';
end;
begin
Result := Next(128) + Next(64) + Next(32) + Next(16) + Next(8) + Next(4) + Next(2) + Next(1);
end;
Tags: binary string, btj, byte string, byte value, byte values, Delphi, hex string, integer values, representations, string function, string representation
Merlin’s Delphi Forge
Leave a comment