HexToBin()十六进制转换二进制 BinToHex()二进制转换十六进制 IntToHex() StrToInt() 要求在字符串前面添加$即可! 把一个整数变成二进制字符串 function IntToBinaryStr(TheVal: LongInt): string; var counter: LongInt; begin {This part is here because we remove leading zeros. That means that a zero value would return an empty string.} if TheVal = 0 then begin result := '0'; exit; end; result := ''; counter := $80000000; {Suppress leading zeros} while ((counter and TheVal) = 0) do begin counter := counter shr 1; if (counter = 0) then break; {We found our first "1".} end; while counter > 0 do begin if (counter and TheVal) = 0 then result := result + '0' else result := result + '1'; counter := counter shr 1; end; end;
BinToHex()二进制转换十六进制
IntToHex()
StrToInt() 要求在字符串前面添加$即可!
把一个整数变成二进制字符串
function IntToBinaryStr(TheVal: LongInt): string;
var
counter: LongInt;
begin
{This part is here because we remove leading zeros. That
means that a zero value would return an empty string.} if TheVal = 0 then begin
result := '0';
exit;
end; result := '';
counter := $80000000; {Suppress leading zeros}
while ((counter and TheVal) = 0) do begin
counter := counter shr 1;
if (counter = 0) then break; {We found our first "1".}
end; while counter > 0 do begin
if (counter and TheVal) = 0 then result := result + '0'
else result := result + '1';
counter := counter shr 1;
end;
end;