Click or drag to resize

Real42Bin Function

Convert a Real4 value to a string containing a 32-bit floating point number.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.10
Syntax
 FUNCTION Real42Bin(
	r4Value AS REAL4
) AS STRING
View Source

Parameters

r4Value
Type: Single
The value to convert.

Return Value

Type: String
Remarks
Real42Bin() is a conversion function that converts a Real4 data type into a 4-byte string.  Typical applications include reading foreign file types in their native format and then saving, reading, decrypting, and transmitting data in their compressed binary form instead of in strings.  Its inverse is Bin2Real4().
Examples
Instead of saving numeric data as strings, this example writes them in a binary format in order to save disk space and possible transmission times:
X#
FUNCTION Compressed() 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
                FWrite3(nh, Real42Bin(123456.789), 4)
                FWrite3(nh, Real42Bin(12 ^ 6), 4)
                FWrite3(nh, Real42Bin(4566.969), 4)
                FClose(nh)
                lSuccess := TRUE
        ELSE
                ? DOSErrString(siError)
        ENDIF
        RETURN lSuccess
See Also