REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: to-hex

to-hex  value  /size  len

Converts a numeric value to a hex issue! datatype (with leading #).


value [integer! tuple!] - Value to be converted


/size - Specify number of hex digits in result

len [integer!]

See also:



The TO-HEX function provides an easy way to convert an integer to a hexidecimal value.

print to-hex 123

The value returned is a string of the ISSUE datatype (not the BINARY datatype). This allows you to convert hex values back to integers:

print to-integer #7B

Note: To convert HTML hex color values (like #80FF80) to REBOL color values, it is easier to do the conversion to binary and then use a base 16 encoding:

to-html-color: func [color [tuple!]] [
    to-issue enbase/base to-binary color 16
print to-html-color 255.155.50

The TO-ISSUE function is just used to add the # to it.

To convert from an HTML color back to a REBOL color tuple, you can use this:

to-rebol-color: func [color [issue!]] [
    to-tuple debase/base color 16
to-rebol-color #FF9B32

If the HTML color value is a string, convert it to an issue first. The function below will work for strings and issues:

to-rebol-color2: func [color [string! issue!]] [
    if string? color [
        if find/match color "#" [color: next color]
        color: to-issue color
    to-tuple debase/base color 16
to-rebol-color2 "#FF9B32"

  TOC < Back Next > - WIP Wiki Feedback Admin