$NCONVERT (ObjectScript)
Synopsis
$NCONVERT(n,format,endian) $NC(n,format,endian)
Parameters
Argument  Description 

n  Any number, which can be specified as a value, a variable, or an expression. Additional limitations on valid values are imposed by the format selected. 
format  One of the following format codes, specified as a quoted string: S1, S2, S4, S8, U1, U2, U4, F4, or F8. 
endian  Optional — A boolean value, where 0 = littleendian and 1 = bigendian. The default is 0. 
Description
$NCONVERT uses the specified format to convert the number n to an encoded string of 8bit characters. The values of these characters are in the range $CHAR(0) through $CHAR(255).
The following are the supported format codes:
S1  Signed integer encoded into a string of one 8bit byte. The value must be in the range 128 through 127, inclusive. 
S2  Signed integer encoded into a string of two 8bit bytes. The value must be in the range 32768 through 32767, inclusive. 
S4  Signed integer encoded into a string of four 8bit bytes. The value must be in the range 2147483648 through 2147483647, inclusive. 
S8  Signed integer encoded into a string of eight 8bit bytes. The value must be in the range 9223372036854775808 through 9223372036854775807, inclusive. 
U1  Unsigned integer encoded into a string of one 8bit byte. The maximum value is 255. 
U2  Unsigned integer encoded into a string of two 8bit bytes. The maximum value is 65535. 
U4  Unsigned integer encoded into a string of four 8bit bytes. The maximum value is 4294967295. 
F4  IEEE floating point number encoded into a string of four 8bit bytes. 
F8  IEEE floating point number encoded into a string of eight 8bit 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 nonnumeric value (contains any nonnumeric characters) Caché performs conversion of a string to a numeric value. A string beginning with a nonnumeric character is converted to 0.
Caché 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=bigendian bit order; 0=littleendian bit order.
WRITE $SYSTEM.Version.IsBigEndian()
$SCONVERT provides the inverse of the $NCONVERT operation.
Examples
The following example converts a series of unsigned numbers to twobyte encoded values:
FOR x=250:1:260 { ZZDUMP $NCONVERT(x,"U2") } QUIT
The following example performs the same operation in bigendian order:
FOR x=250:1:260 { ZZDUMP $NCONVERT(x,"U2",1) } QUIT
See Also

$SCONVERT function