REBOL Document

Debase - Function Summary


Summary:

Converts a string from a different base representation to binary.

Usage:

debase value

Arguments:

value - The string to convert (must be: any-string)

Refinements:

/base - Allow a selection of a different base for conversion

base-value - The base to convert from: 64, 16, or 2

Description:

Converts from an encoded string to the binary value. Primarily used for BASE-64 decoding.

The /BASE refinement allows selection of number base as 64, 16, 2. Default is base64.


    probe debase "MTIzNA=="
    #{31323334}


    probe debase/base "12AB C456" 16
    #{12ABC456}


    enbased: probe enbase "a string of text"
    "YSBzdHJpbmcgb2YgdGV4dA=="


    probe string? enbased         ; enbased value is a string
    true


    debased: probe debase enbased ; converts to binary value
    #{6120737472696E67206F662074657874}


    probe to-string debased       ; converts back to original string
    "a string of text"

If the input value cannot be decoded (such as when missing the proper number of characters), a NONE is returned.


    probe debase "100"
    none


    probe debase "1001"
    #{D74D35}

Related:

dehex - Converts URL-style hex encoded (%xx) strings.
enbase - Converts a string to a different base representation.


<Back | Index | Next>

Copyright 2004 REBOL Technologies