REBOL [
    Title: "Hex byte"
    Purpose: {Convert a one-character string to a two-character
    display of its hex value, suitable for printing.}
]

;; [---------------------------------------------------------------------------]
;; [ This little function is part of a project to print a string of bytes      ]
;; [ that has some unprintable characters.  It takes one character and         ]
;; [ returns two, that are the hex representation of the byte.                 ]
;; [---------------------------------------------------------------------------]

HEX-BYTE: func [
    BYTE
] [
    return reverse copy/part reverse to-string to-hex to-integer to-binary BYTE 2
]

;;Uncomment to test
;print ["X =" HEX-BYTE "X"]
;print ["7 =" HEX-BYTE "7"]
;print ["! =" HEX-BYTE "!"]
;print ["[ =" HEX-BYTE "["]
;print ["# =" HEX-BYTE "#"]
;halt