Delphi 无符号整型转换成二进制位类

  • 函数类型: 自定义函数

  • 函数说明:

无符号整型转换成二进制位类


  • 代码如下:



 function IntegerToBits(const AValue: Integer): TBits;

  function BitsToArray: TArray;
  const
    BitsSize = 32;
  var
    X, Y: Integer;
  begin
    SetLength(Result, BitsSize);
    X := 1;
    Y := 1;
    repeat
      Result[X - 1] := Y;
      // ShowMessageFmt('%d=%x', [X, Y]);
      Y := Y * 2;
      Inc(X);
    until X > BitsSize;
  end;

const
  BitsSize = 32;
  Bits: array [0 .. BitsSize - 1] of UInt32 = ($1, $2, $4, $8, $10, $20, $40,
    $80, $100, $200, $400, $800, $1000, $2000, $4000, $8000, $10000, $20000,
    $40000, $80000, $100000, $200000, $400000, $800000, $1000000, $2000000,
    $4000000, $8000000, $10000000, $20000000, $40000000, $80000000);
var
  I: Integer;
begin
  Result := TBits.Create;
  Result.Size := BitsSize;
  for I := 0 to Result.Size - 1 do
    Result[I] := (AValue and Bits[I]) = Bits[I];
end;



  • 用法示例:

无 



《学习大师原创文档,请勿转载,侵权必究》





联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678