5

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 how to use delphi to this without returning out of range error.

Muda

Community
  • 1
  • 1

2 Answers2

4

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)

Community
  • 1
  • 1
Johan
  • 74,508
  • 24
  • 191
  • 319
1

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)

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122