数据类型问题? a : string;b : integer;c : Single;如何将a,b,c连接到一起,生成一个16进制的串 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 s:=a+b+c;//不行则用a+IntToStr(b)+FloatToStr(c);f:=StrToFloat(s);result:=Format('%x',[f]); 我要的是十六进制的串,就是a,b,c在内存中的内容,然后将他们连续写入外部的一个存储器上。 我要的是十六进制的串,就是a,b,c在内存中的内容,然后将他们连续写入外部的一个存储器上。 给你个参考资料,我用它实现了不少转换功能,你看看,定有帮助const MinBase = 2; MaxBase = 36; function NumToStr (num, len, base: Integer; neg: Boolean; fill: char): string; // num = 要转换的数 // len = 生成字符串的最小长度// base = 进制数 2 = 二进制// neg = 是否允许负数// fill = 填充字符用于补满字符串长度// // 用法: // NumToStr (45, 8, 2, false, ''0'') > ''00101101'' // NumToStr (45, 4, 8, false, ''0'') > ''0055'' // NumToStr (45, 4, 10, false, '' '') > '' 45'' // NumToStr (45, 4, 16, false, ''0'') > ''002D'' // NumToStr (45, 0, 36, false, '' '') > ''19'' // var s: string; digit: Integer; begin num:= ABS (num); if ((base >= MinBase) and (base <= MaxBase)) then begin s:= ''''; repeat digit:= num mod base; if digit < 10 then Insert (CHR (digit + 48), s, 1) else Insert (CHR (digit + 55), s, 1); num:= num div base; until num = 0; if neg then Insert (''-'', s, 1); while Length(s) < len do Insert (fill, s, 1); end; Result:= s; end; 从字符串转换回数: function StrToNum (const s: string; base: Integer; neg: Boolean; max: Integer): Integer; // s = 要转换的字符串// base = 进制数// neg = 是否为负数// max = 要转换的最大数// // 用法: // i:= StrToNum (''00101101'', 2, false, MaxInt); // i:= StrToNum (''002D'', 16, false, MaxInt); // i:= StrToNum (''-45'', 10, true, MaxInt); // i:= StrToNum (''ZZ'', 36, true, MaxInt); // var negate, done: Boolean; i, ind, len, digit, mmb: Integer; c: Char; mdb, res: Integer; begin res:= 0; i:= 1; digit:= 0; if (base >= MinBase) and (base <= MaxBase) then begin mmb:= max mod base; mdb:= max div base; len:= Length (s); negate:= False; while (i <= len) and (s[i] = '' '') do Inc (i); if neg then begin case s[i] of ''+'': Inc (i); ''-'': begin Inc (i); negate:= TRUE; end; end; (* CASE *) end; (* IF neg *) done:= len > i; while (i <= len) and done do begin c:= Upcase (s[i]); case c of ''0''..''9'': digit:= ORD(c) - 48; ''A''..''Z'': digit:= ORD(c) - 55; else done:= FALSE end; (* CASE *) done:= done and (digit < base); if done then begin done:= (res < mdb) or ((res = mdb) and (digit <= mmb)); IF done then begin res:= res * base + digit; Inc (i); end; (* IF done *) end; (* IF done *) end; (* WHILE *) if negate then res:= - res; end; (* IF done *) Result:= res; end; var a: string; b: integer; c: single; outstr: string; i: integer; pint: ^integer;begin outstr := ''; for i := 1 to Length(a) do begin outstr := outstr + IntToHex(Byte(a[i]), 2); end; outstr := outstr + IntToHex(0, 2);//串结尾的0 outstr := outstr + IntToHex(b, 8); pint := @c; b := pint^; outstr := outstr + IntToHex(b, 8);end; ??? FastReport 简单主报表 子报表问题 ??? toolbutton颜色和使能控制方法 关于读nero的存档文件 为何重新读入流会报地址错误??急! 简单update 语句求教 求助多谢! 如何实现窗体总在最前,且总被激活,以及窗体之间控制按钮的可操作? 我是D新手,请问学D重点在哪??? 如何将Memo中的所有行添加到数据库TEXT类型(SQL SERVER)字段当中 请问有用delphi6.0中的web broker或者websnap编过程序吗? 请问ListView中的记录如何与记录文件中的相对应? 应用程序移植时的动态连接文件问题。
f:=StrToFloat(s);
result:=Format('%x',[f]);
MaxBase = 36; function NumToStr (num, len, base: Integer; neg: Boolean;
fill: char): string;
// num = 要转换的数
// len = 生成字符串的最小长度// base = 进制数 2 = 二进制
// neg = 是否允许负数// fill = 填充字符用于补满字符串长度//
// 用法:
// NumToStr (45, 8, 2, false, ''0'') > ''00101101''
// NumToStr (45, 4, 8, false, ''0'') > ''0055''
// NumToStr (45, 4, 10, false, '' '') > '' 45''
// NumToStr (45, 4, 16, false, ''0'') > ''002D''
// NumToStr (45, 0, 36, false, '' '') > ''19''
//
var s: string;
digit: Integer;
begin
num:= ABS (num);
if ((base >= MinBase) and (base <= MaxBase)) then begin
s:= '''';
repeat
digit:= num mod base;
if digit < 10 then Insert (CHR (digit + 48), s, 1)
else Insert (CHR (digit + 55), s, 1);
num:= num div base;
until num = 0;
if neg then Insert (''-'', s, 1);
while Length(s) < len do Insert (fill, s, 1);
end;
Result:= s;
end; 从字符串转换回数: function StrToNum (const s: string; base: Integer;
neg: Boolean; max: Integer): Integer;
// s = 要转换的字符串
// base = 进制数
// neg = 是否为负数// max = 要转换的最大数//
// 用法:
// i:= StrToNum (''00101101'', 2, false, MaxInt);
// i:= StrToNum (''002D'', 16, false, MaxInt);
// i:= StrToNum (''-45'', 10, true, MaxInt);
// i:= StrToNum (''ZZ'', 36, true, MaxInt);
//
var negate, done: Boolean;
i, ind, len, digit, mmb: Integer;
c: Char;
mdb, res: Integer;
begin
res:= 0; i:= 1; digit:= 0;
if (base >= MinBase) and (base <= MaxBase) then begin
mmb:= max mod base;
mdb:= max div base;
len:= Length (s);
negate:= False;
while (i <= len) and (s[i] = '' '') do Inc (i);
if neg then begin
case s[i] of
''+'': Inc (i);
''-'': begin Inc (i); negate:= TRUE; end;
end; (* CASE *)
end; (* IF neg *)
done:= len > i;
while (i <= len) and done do begin
c:= Upcase (s[i]);
case c of
''0''..''9'': digit:= ORD(c) - 48;
''A''..''Z'': digit:= ORD(c) - 55;
else done:= FALSE
end; (* CASE *)
done:= done and (digit < base);
if done then begin
done:= (res < mdb) or ((res = mdb) and (digit <= mmb));
IF done then begin
res:= res * base + digit;
Inc (i);
end; (* IF done *)
end; (* IF done *)
end; (* WHILE *)
if negate then res:= - res;
end; (* IF done *)
Result:= res;
end;
a: string;
b: integer;
c: single;
outstr: string;
i: integer;
pint: ^integer;
begin
outstr := '';
for i := 1 to Length(a) do
begin
outstr := outstr + IntToHex(Byte(a[i]), 2);
end;
outstr := outstr + IntToHex(0, 2);//串结尾的0
outstr := outstr + IntToHex(b, 8);
pint := @c;
b := pint^;
outstr := outstr + IntToHex(b, 8);
end;