Function Bin2u() Foundation
Converts a 32 bit unsigned integer to a numeric value.
Bin2u( <cUnsignedInt> ) --> nUnsignedInt
The conversion function Bin2u() returns an integer numeric value in the range of 0 to 4294967265.
Bin2u() converts binary numbers within character strings to their numeric values. The counterpart of Bin2u() is the function U2bin() which converts a positive integer to a 4 byte character string.
The value range of Bin2u() or U2bin() is that for a 32 bit unsigned integer. Similar conversion functions are Bin2i(), Bin2l() and Bin2w().
Bin2u() is frequently used in connection with the low level file functions. This is sometimes done to allow definition of special or unique file formats, or to provide data compression when very large integer numeric values are being stored.
// The example demonstrates a simple method of data
// compression for numeric values within a known range
// (in this case they are positive integers).
PROCEDURE Main
LOCAL i, cNumeric:="", cCompressed := ""
FOR i:=1 TO 10
cNumeric += Str( 1000000*i , 9 )
cCompressed += U2bin( 1000000*i )
NEXT
? Len( cNumeric ) // result: 90
? Len( cCompressed ) // result: 40
FOR i:=1 TO 10
? Val( SubStr( cNumeric, 9*(i-1)+1, 9 ) )
? Bin2u( SubStr( cCompressed, 4*(i-1)+1, 4 ) )
NEXT
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.