Converts a number to a binary value encoded in a string of 8-bit characters.
Description
$NCONVERT uses the specified format to convert the number n to an encoded string of 8-bit characters. The values of these characters are in the range $CHAR(0) through $CHAR(255).
The following are the supported format codes:
Code |
Description |
S1 |
Signed integer encoded into a string of one 8-bit byte. The value must be in the range -128 through 127, inclusive. |
S2 |
Signed integer encoded into a string of two 8-bit bytes. The value must be in the range -32768 through 32767, inclusive. |
S4 |
Signed integer encoded into a string of four 8-bit bytes. The value must be in the range -2147483648 through 2147483647, inclusive. |
S8 |
Signed integer encoded into a string of eight 8-bit bytes. The value must be in the range -9223372036854775808 through 9223372036854775807, inclusive. |
U1 |
Unsigned integer encoded into a string of one 8-bit byte. The maximum value is 255. |
U2 |
Unsigned integer encoded into a string of two 8-bit bytes. The maximum value is 65535. |
U4 |
Unsigned integer encoded into a string of four 8-bit bytes. The maximum value is 4294967295. |
F4 |
IEEE floating point number encoded into a string of four 8-bit bytes. |
F8 |
IEEE floating point number encoded into a string of eight 8-bit bytes. |
Values beyond the range of format limits result in a <VALUE OUT OF RANGE> error. Specifying a negative number for an Unsigned format results in a <VALUE OUT OF RANGE> error. If n is a non-numeric value (contains any non-numeric characters) InterSystems IRIS performs conversion of a string to a numeric value. A string beginning with a non-numeric character is converted to 0.
InterSystems IRIS rounds a fractional number to an integer value for all formats except F4 and F8.
You can use the IsBigEndian()Opens in a new tab class method to determine which bit ordering is used on your operating system platform: 1=big-endian bit order; 0=little-endian bit order.
WRITE $SYSTEM.Version.IsBigEndian()
$SCONVERT provides the inverse of the $NCONVERT operation.