var testarr: BoolArray;function TransBool(BArr: integer): BoolArray; var idx: integer; begin SetLength(Result, 32); idx := 0; while BArr <> 0 do begin Result[idx] := Boolean(BArr and 1); BArr := BArr shr 1; Inc(idx); end; SetLength(Result, idx); end;procedure TForm1.Button1Click(Sender: TObject); begin testarr := TransBool(2); end;
type BoolArray = array of Boolean;
写两个函数来转换:function Dec2Boolean(d: Word): String; const BOOLCHAR : array[0..1] of Char = ('F', 'T'); begin Result := ''; repeat if Result <> '' then Result := ',' + Result; Result := BOOLCHAR[d mod 2] + Result; d := d div 2; until d = 0; end;function Boolean2Dec(B: String): Word; var i : Integer; begin Result := 0; for i := 0 to Length(B) div 2 do begin Result := Result * 2; if (B[i * 2 + 1]) = 'T') or (B[i * 2 + 1]) = 't') then Result := Result + 1; end; end; 调用的例子: ShowMessage (Dec2Boolean(4)); ShowMessage (IntToStr(Boolean2Dec('T,F,F,F')));
BoolArray to integer 呢,呵呵
type BoolArray = array of Boolean; PBoolArray = ^BoolArray; end; function A2W(const src: PBoolArray; SrcLen: word): WORD; function W2A(const src: word; var dest: PBoolArray; const destlen: word): boolean;...其他的自己补上
var
testarr: BoolArray;function TransBool(BArr: integer): BoolArray;
var
idx: integer;
begin
SetLength(Result, 32);
idx := 0;
while BArr <> 0 do
begin
Result[idx] := Boolean(BArr and 1);
BArr := BArr shr 1;
Inc(idx);
end;
SetLength(Result, idx);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
testarr := TransBool(2);
end;
BoolArray = array of Boolean;
const
BOOLCHAR : array[0..1] of Char = ('F', 'T');
begin
Result := '';
repeat
if Result <> '' then Result := ',' + Result;
Result := BOOLCHAR[d mod 2] + Result;
d := d div 2;
until d = 0;
end;function Boolean2Dec(B: String): Word;
var
i : Integer;
begin
Result := 0;
for i := 0 to Length(B) div 2 do
begin
Result := Result * 2;
if (B[i * 2 + 1]) = 'T') or (B[i * 2 + 1]) = 't') then Result := Result + 1;
end;
end;
调用的例子: ShowMessage (Dec2Boolean(4));
ShowMessage (IntToStr(Boolean2Dec('T,F,F,F')));
BoolArray to integer 呢,呵呵
BoolArray = array of Boolean;
PBoolArray = ^BoolArray;
end;
function A2W(const src: PBoolArray; SrcLen: word): WORD;
function W2A(const src: word; var dest: PBoolArray; const destlen: word): boolean;...其他的自己补上