Click or drag to resize

W2Bin Function

Convert a word to a string containing a 16-bit unsigned integer.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.10
Syntax
 FUNCTION W2Bin(
	wValue AS WORD
) AS STRING
View Source

Parameters

wValue
Type: UInt16
The value to convert.  Decimal values are truncated.

Return Value

Type: String
Remarks
W2Bin() is a conversion function that converts a word into a 2-byte string.  Typical applications include reading foreign file types in their native format and then saving, reading, decrypting, and transmitting numeric data in their compressed binary form instead of in strings.  Its inverse is Bin2W().
Examples
This example uses W2Bin() to store the current procedure line to a debugging file:
X#
FUNCTION ErrorLines() AS LOGIC
        LOCAL nh
        LOCAL lSuccess := FALSE AS LOGIC
        nh := FOpen2("data.bin", FO_READWRITE)
        // Assumes that file debug.bin already exists
        IF nh != F_ERROR
                FWrite(nh, W2Bin(ProcLine()))
                FWrite(nh, W2Bin(ProcLine(1)))
                FClose(nh)
                lSuccess := TRUE
        ELSE
                ? "An error occurred when opening debug.bin"
                FError()
        ENDIF
        RETURN lSuccess
See Also