你自己再修改吧 function inttoBin(i,len: integer): string; begin while i <> 0 do begin //i mod 2取模,再使用format格式化 result := Format('%d' + result, [i mod 2]); i := i div 2 end ; while length(Result)<len do Result:='0'+Result; end; var int, i: Integer; intbytes: array[0..3] of Byte; str: string; strbytes: array of Char; begin int := 123456789; Move(int, intbytes, 4); Memo1.Lines.Add(inttoBin(intbytes[3],8)); Memo1.Lines.Add(inttoBin(intbytes[2],8)); Memo1.Lines.Add(inttoBin(intbytes[1],8)); Memo1.Lines.Add(inttoBin(intbytes[0],8)); Memo1.Lines.Add(inttoBin(intbytes[3],8) + inttoBin(intbytes[2],8) + inttoBin(intbytes[1],8) + inttoBin(intbytes[0],8)); str := 'ABCDEFGhijk'; SetLength(strbytes, Length(str)); for i := 1 to Length(str) do begin strbytes[i - 1] := str[i]; Memo1.Lines.Add(strbytes[i - 1]); end; end;
const id=12345678; const str='ABCDEFGH'; var i:integer; Arr1,Arr2:array of Byte; begin setlength(Arr1,Length(inttostr(id))); setlength(Arr2,Length(str)); move(Pchar(inttostr(id))^,arr1[0],Length(inttostr(id))); move(Pchar(str)^,arr2[0],Length(str));{两个数组怎么连接自己处理 for i:=low(arr1) to high(arr1) do memo1.Lines.Add(chr(arr1[i])); for i:=low(arr2) to high(arr2) do memo1.Lines.Add(chr(arr2[i])); } end;
var B : array [0..3] of Byte; n : integer; begin n := 673261280; PInteger(@B)^ := n; //B[0]=224 , B[1]=38 B[2]=33 B[3]=40 end;
!!!!!!!! 你算是懒到家了哦 var B : array [0..3] of Byte; n : integer; S : String; begin n := 673261280; PInteger(@B)^ := n; //B[0]=224 , B[1]=38 B[2]=33 B[3]=40 for n:=0 to 3 do S := S + IntToStr(B[n]) + ','; Delete(S , Length(S) , 1); Edit.Text := S; end;
var S : AnsiString; B : array [0..23] of Byte; ... //PInteger(@B)^ := n; //B[0]=224 , B[1]=38 B[2]=33 B[3]=40 //以上是前面的代码 S := '� 灂�+F"L�N`_�4'; //这里需要那个20字节的字符串 if Length(S)=20 then CopyMemory(@B[4] , Pointer(S) , 20);
begin
while i <> 0 do
begin //i mod 2取模,再使用format格式化
result := Format('%d' + result, [i mod 2]);
i := i div 2
end ;
while length(Result)<len do
Result:='0'+Result;
end;
var
int, i: Integer;
intbytes: array[0..3] of Byte;
str: string;
strbytes: array of Char;
begin
int := 123456789;
Move(int, intbytes, 4);
Memo1.Lines.Add(inttoBin(intbytes[3],8));
Memo1.Lines.Add(inttoBin(intbytes[2],8));
Memo1.Lines.Add(inttoBin(intbytes[1],8));
Memo1.Lines.Add(inttoBin(intbytes[0],8));
Memo1.Lines.Add(inttoBin(intbytes[3],8) + inttoBin(intbytes[2],8) + inttoBin(intbytes[1],8) + inttoBin(intbytes[0],8));
str := 'ABCDEFGhijk';
SetLength(strbytes, Length(str));
for i := 1 to Length(str) do
begin
strbytes[i - 1] := str[i];
Memo1.Lines.Add(strbytes[i - 1]);
end;
end;
如673261280为例,转出来就是四个字节:“224,38,33,40”
这应该是什么类型,怎么转?
const str='ABCDEFGH';
var
i:integer;
Arr1,Arr2:array of Byte;
begin
setlength(Arr1,Length(inttostr(id)));
setlength(Arr2,Length(str)); move(Pchar(inttostr(id))^,arr1[0],Length(inttostr(id)));
move(Pchar(str)^,arr2[0],Length(str));{两个数组怎么连接自己处理
for i:=low(arr1) to high(arr1) do
memo1.Lines.Add(chr(arr1[i]));
for i:=low(arr2) to high(arr2) do
memo1.Lines.Add(chr(arr2[i]));
}
end;
B : array [0..3] of Byte;
n : integer;
begin
n := 673261280;
PInteger(@B)^ := n;
//B[0]=224 , B[1]=38 B[2]=33 B[3]=40
end;
你算是懒到家了哦
var
B : array [0..3] of Byte;
n : integer;
S : String;
begin
n := 673261280;
PInteger(@B)^ := n;
//B[0]=224 , B[1]=38 B[2]=33 B[3]=40
for n:=0 to 3 do
S := S + IntToStr(B[n]) + ',';
Delete(S , Length(S) , 1);
Edit.Text := S;
end;
十六进制字符窜“871D0A9E95ABA22B4604224CFBA24E605FABBC34”,把它转成二进制的字节数组,是这样一串奇怪的字符串“� 灂�+F"L�N`_�4”。如果你是用VB的话,其实就转为十进制。每二个字符转为一个字节。代码:CLng("&H"&"87")结果是:135。转完之后把它拷贝到字节数组里面,前面加上userid,以“673261280”为例,转为unsigned char,四个字节:“224,38,33,40”加起来就是24个字节。
这段话最后说的是24个字节,减去“673261280”的四个字节应该是20个字节,那“871D0A9E95ABA22B4604224CFBA24E605FABBC34”到底转成了什么类型的,怎么转? 麻烦你了,确实不清楚!
前面有ID转换过来4个字节,加上这40字节转换成的20个字节,一共24字节,
而你的
"� 灂�+F"L�N`_�4" 只有16个字节,怎么回事?
哦,你提醒了我,我刚才编译了一下?
灂+F"LN`_4|20 是20个字符,(|20是我加的统计)按这么理解就应该是"673261280"转成的数组和这个“"� 灂�+F"L�N`_�4”转的数组加起来。请问,“"� 灂�+F"L�N`_�4”这个怎么转入数组才正确,是strcopy吗?,前面的数组(byte)怎么和这个数组(应该是char吧?)能加起来?
S : AnsiString;
B : array [0..23] of Byte;
...
//PInteger(@B)^ := n;
//B[0]=224 , B[1]=38 B[2]=33 B[3]=40
//以上是前面的代码
S := '� 灂�+F"L�N`_�4'; //这里需要那个20字节的字符串
if Length(S)=20 then
CopyMemory(@B[4] , Pointer(S) , 20);