Hexadecimal Value Ranges
-
Hex numbers in the range 0 … 7FFF FFFF are positive
INTEGER
s with values between 0 … 2147483647 decimal.To coerce a number toBIGINT
, prepend enough zeroes to bring the total number of hex digits to nine or above.That changes the type but not the value. -
Hex numbers between 8000 0000 … FFFF FFFF require some attention:
-
When written with eight hex digits, as in
0x9E44F9A8
, a value is interpreted as 32-bitINTEGER
.Since the leftmost bit (sign bit) is set, it maps to the negative range -2147483648 … -1 decimal. -
With one or more zeroes prepended, as in
0x09E44F9A8
, a value is interpreted as 64-bitBIGINT
in the range 0000 0000 8000 0000 … 0000 0000 FFFF FFFF.The sign bit is not set now, so they map to the positive range 2147483648 … 4294967295 decimal.
Thus, in this range, and for 16 vs 16+ digits, prepending a mathematically insignificant 0 results in a different value.This is something to be aware of.
-
-
Hex numbers between 0 0000 0001 … 7FFF FFFF FFFF FFFF are all positive
BIGINT
. -
Hex numbers between 8000 0000 0000 0000 … FFFF FFFF FFFF FFFF are all negative
BIGINT
. -
Hex numbers between 0 0000 0000 0000 0001 … 7FFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF are all positive
INT128
-
Hex numbers between 8000 0000 0000 0000 0000 0000 0000 0000 … FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF are all negative
INT128
-
A
SMALLINT
cannot be written in hex, strictly speaking, since even0x0
and0x1
are evaluated asINTEGER
.However, if you write a positive integer within the 16-bit range0x0000
(decimal zero) to0x7FFF
(decimal 32767) it will be converted toSMALLINT
transparently.It is possible to write to a negative
SMALLINT
in hex, using a 4-byte hex number within the range0xFFFF8000
(decimal -32768) to0xFFFFFFFF
(decimal -1).