Delphi Programming to convert 66-bit value (Hex) to Decimal [duplicate]
Possible Duplicate:
Large numbers in Pascal (Delphi)
I am trying to convert a 66bit value to decimal.
I note that the largest data type in delphi in int64 which can only allow 64bit data. example of delphi code for such conversion is
result := strtoInt64('FFFFABCDEFF123456');
Please advice 开发者_如何学Chow to use delphi to this without returning out of range error.
Muda
Decimal in Delphi is called currency
it uses 8 bytes = 64 bits.
You'll have to create your own type, see this article: http://www.delphi3000.com/articles/article_3772.asp
It describes how to create a 128bit integer.
Here's a bignum lib for Delphi: http://cc.embarcadero.com/item/27789
See also this question: Large numbers in Pascal (Delphi)
If you can afford having some rounding errors, you can use the Extended
type. That's an easy solution. I remember reading somewhere that it won't be supported in 64bit Delphi anymore though, so I personally wouldn't use it if it can be avoided.
Anyway, do you really want to do calculations on your number? Are you sure you don't just want to have an array (of bytes for example)? If that is the case, you should look at HexToBin()
.
Documentation: http://docwiki.embarcadero.com/VCL/en/Classes.HexToBin
Example where you can see it in use: http://docwiki.embarcadero.com/CodeExamples/en/HexEncoding_(Delphi)
精彩评论