Syntax
hexCFString =
hex(
expr )
hexPascalString =
hex$(
expr )
Description
This 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 or hex$ will not represent the true value of expr.
In FutureBasic, integers are stored in standard "2's-complement" format, and the values returned by hex or hex$ reflect this storage scheme. You need to keep this in mind when interpreting the results of hex or hex$, especially when expr is a negative number. For example: hex and hex$(-3)
return "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" + hexPascalString)
intVar
can be a (signed or unsigned) byte variable, short-integer variable or long-integer variable. Byte variables can handle a hexPascalString
up to 2 characters in length; short-integer variables can handle a hexPascalString
up to 4 characters in length; long-integer variables can handle a hexPascalString
up to 8 characters in length.
See also
oct; bin; defstr; val&