在delphi中将十六进制数转换为十进制值 [英] Convert hex str to decimal value in delphi
问题描述
例如:
我有一个问题,用Delphi转换整数值的十六进制值的字符串表示法
$ FC75B6A9D025CB16给我802829546当我使用的功能:
Abs(StrToInt64('$ FC75B6A9D025CB16'))
但如果我使用来自Windows的calc程序,结果是:18191647110290852630
所以我的问题是:谁是对的?我还是计算?
有没有人有这种问题?
我不得不使用名为DFF库的Delphi库,因为我在Delphi6上工作,而这个版本中不存在类型 Uint64
。
主页
这是我的代码,将十六进制值的字符串转换为十进制值的字符串:
您需要添加 UBigIntsV3
您的单位使用。
函数StrHexaToUInt64Str(const stringHexadecimal:String):string;
var
unBigInteger:TInteger;
begin
unBigInteger:= TInteger.Create;
try
// stringHexadecimal参数没有'$'符号传递
// ex:stringHexadecimal:='FFAA0256'而不是'$ FFAA0256'
unBigInteger.AssignHex(stringHexadecimal );
//布尔值确定是否要添加一千个分隔符。
结果:= unBigInteger.converttoDecimalString(false);
finally
unBigInteger.free;
结束
结束
I've got a problem to convert a string representation of an hex value in integer value with Delphi.
for example:
$FC75B6A9D025CB16 give me 802829546 when i use the function:
Abs(StrToInt64('$FC75B6A9D025CB16'))
but if i use the calc program from Windows, the result is: 18191647110290852630
So my question is: who's right? me, or the calc?
Does anybody already have this kind of problem?
I had to use a Delphi library named "DFF Library" because I work on Delphi6 and the type Uint64
does not exist in this version.
Main page
Here's my code to transform a string of hexadecimal value to a string of decimal value:
You need to add UBigIntsV3
to your uses in your unit.
function StrHexaToUInt64Str(const stringHexadecimal: String): string;
var
unBigInteger:TInteger;
begin
unBigInteger:=TInteger.Create;
try
// stringHexadecimal parameter is passed without the '$' symbol
// ex: stringHexadecimal:='FFAA0256' and not '$FFAA0256'
unBigInteger.AssignHex(stringHexadecimal);
//the boolean value determine if we want to add the thousand separator or not.
Result:=unBigInteger.converttoDecimalString(false);
finally
unBigInteger.free;
end;
end;
这篇关于在delphi中将十六进制数转换为十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!