REBOL Document

To-hex - Function Summary


Summary:

Converts an integer to a hex issue!.

Usage:

to-hex value

Arguments:

value - Value to be converted (must be: integer)

Description:

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


    print to-hex 123
    0000007B

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
    123

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
    FF9B32

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"

Related:

to-integer


<Back | Index | Next>

Copyright 2004 REBOL Technologies