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.6
Syntax
 FUNCTION Real42Bin(
	r4Value AS REAL4
) AS STRING
Request Example 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#
 1FUNCTION Compressed() AS LOGIC
 2    LOCAL nh
 3    LOCAL lSuccess := FALSE AS LOGIC
 4    nh := FOpen2("data.bin", FO_READWRITE)
 5    // Assumes that file debug.bin already exists
 6    IF nh != F_ERROR
 7        FWrite3(nh, Real42Bin(123456.789), 4)
 8        FWrite3(nh, Real42Bin(12 ^ 6), 4)
 9        FWrite3(nh, Real42Bin(4566.969), 4)
10        FClose(nh)
11        lSuccess := TRUE
12    ELSE
13        ? DOSErrString(siError)
14    ENDIF
15    RETURN lSuccess
See Also