IntToBin(2-16進制轉換函數)
2019-11-18 18:07:56
供稿:網友
 
(****Value是要轉換的十進制數,Count是輸出的二進制位數,默認32位****)
function IntToBin(Value: Integer; Count: Integer=32): string;
var
  iTemp: Integer;
begin
  Result := '';
  while Count>0 do
  begin
    iTemp := Value shr (Count-1) and 1;
    case iTemp of
      1: Result := Result+'1';
      0: Result := Result+'0';
    end;
    Dec(Count);
  end;
end;
自己寫的,不知有否漏洞,測試了一下
ShowMessage(IntToBin(-1,8));  //輸出11111111
ShowMessage(IntToBin(333333)); //輸出00000000000001010001011000010101