Futurebasic/Language/Reference/hexstring
HEX$
editSyntax
edithexString$ = HEX$(<i>expr)
Description
editThis function returns a string of hexadecimal digits which represent the integer value of expr
. The returned string will consist of either 2, 4 or 8 characters, depending on which of DEFSTR BYTE
, DEFSTR WORD
or DEFSTR LONG
is currently in effect. Note that if the value of expr
is too large to fit in a hex string of the currently selected size, the string returned by HEX$
will not represent the true value of expr
.
In FB, integers are stored in standard "2's-complement" format, and the values returned by HEX$
reflect this storage scheme. You need to keep this in mind when interpreting the results of HEX$
, especially when expr
is a negative number. For example: HEX$(-3)
returns "FD
" when DEFSTR BYTE
is in effect; "FFFD
" when DEFSTR WORD
is in effect; and "FFFFFFFD
" when DEFSTR LONG
is in effect.
Note: To convert a string of hex digits into an integer, use the following technique:
intVar = VAL&("&H" + hexString$)
intVar
can be a (signed or unsigned) byte variable, short-integer variable or long-integer variable. Byte variables can handle a hexString$
up to 2 characters in length; short-integer variables can handle a hexString$
up to 4 characters in length; long-integer variables can handle a hexString$
up to 8 characters in length.
See Also
edit; BIN$; DEF STRBYTE/WORD/LONG; VAL