Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare an Int64 constant?

i'm trying to define a constant in Delphi:

const
   FNV_offset_basis = 14695981039346656037;

And i get the error: Integer constant too large

Note: 14,695,981,039,346,656,037 decimal is equal to 0x14650FB0739D0383 hex.

How can i declare this Int64 constant?

Some other things i've tried:

const
   FNV_offset_basis: Int64 = 14695981039346656037;
   FNV_offset_basis = Int64(14695981039346656037);
   FNV_offset_basis: Int64 = Int64(14695981039346656037);


var
   offset: LARGE_INTEGER;
begin
   //recalculate constant every function call
   offset.LowPart = $739D0383;
   offset.HighPart = $14650FB0;

Correction

My fundamental assumption was wrong.

Pasting 14695981039346656037 into Windows 7 Calculator, and converting to hex, led me to believe that the hex equivalent of 14695981039346656037 is 0x14650FB0739D0383:

enter image description here

That is incorrect.

So when i saw a 16-digit hex value, with the high bit not set, i presumed it could fit in a 64-bit signed integer.

In reality the hex equivalent of 14695981039346656037 is...something else. Rob, you were right! (probably)

like image 378
Ian Boyd Avatar asked Apr 24 '12 17:04

Ian Boyd


People also ask

How do I declare Int64?

You can declare an Int64 variable and assign it a literal integer value that is within the range of the Int64 data type. The following example declares two Int64 variables and assigns them values in this way. You can assign the value of an integral type whose range is a subset of the Int64 type.

How do you declare a 64-bit integer in C++?

Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intN type specifier, where N is 8, 16, 32, or 64.

How do you declare a constant in Delphi?

To declare a record constant, specify the value of each field - as fieldName: value , with the field assignments separated by semicolons - in parentheses at the end of the declaration. The values must be represented by constant expressions.

Does Int64 have decimals?

INT64. Integers are always whole numbers; they have no decimals or fractional components.


2 Answers

Your hex conversion in the question is incorrect. That number is actually $cbf29ce484222000 and does not fit into a signed 64 bit integer. You would need an unsigned 64 bit integer to represent it. There is no unsigned UInt64 in Delphi 5 and so you are out of luck. There is no integral data type that can represent that number in your version of Delphi.

You could perhaps interpret the bit pattern as a signed value if that does what you need. In that case you would have a negative number.

like image 166
David Heffernan Avatar answered Nov 15 '22 06:11

David Heffernan


That number is bigger than a signed 64-bit integer can hold. Have you tried using UInt64 instead?

like image 25
Jon Skeet Avatar answered Nov 15 '22 05:11

Jon Skeet