REBOL 3.0

TO-HEX considerations for 64 bit integers

Carl Sassenrath, CTO
REBOL Technologies
7-Jun-2006 1:41 GMT

Article #0031
Main page || Index || Prior Article [0030] || Next Article [0032] || 18 Comments || Send feedback

When using to-hex in REBOL 3.0 be aware that the returned hexidecimal string will be longer due to the use of 64 bit integers.

For example, in REBOL 2.6, 32 bit integers resulted in:

>> to-hex 1
== #00000001

In REBOL 3.0, the results will be appropriate to 64 bit integers:

>> to-hex 1
== #0000000000000001

To help deal with this, a /size refinement has been added. It specifies the number of hex digits to return. For example, to request the same result as in REBOL 2.5, you can write:

>> to-hex/size 1 8
== #00000001

to-hex/size -1 8
== #FFFFFFFF

Of course, for numbers larger than 32 bits, this is problematic because the result will be clipped at eight digits.

Also, for convenience, the to-hex function has been expanded to allow character and tuple values. For example:

>> to-hex first "REBOL"
== #52

>> to-hex first ##{005200450042004f004c} ; unicode
== #0052

The tuple datatype conversion to hex is handy for converting REBOL colors to HTML color values:

>> to-hex 255.150.50
== #FF9632

(But be careful if the value contains an alpha value.)

18 Comments

REBOL 3.0
Updated 19-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net