Main Index : Reference :

liee2mem()


Description

Converts a float variable into a 64 bit IEE double float and inserts it at a certain position in a byte array.

Definition

[bool] liee2mem([float] value, [bytes] mem, [int] pos, [int] byteorder)

Parameters

value is a float.
mem is a byte array.
pos is the position within mem.
byteorder is either big endian or little endian.

Function

liee2mem() converts value into a 64 bit IEE double float and inserts it at the position pos in the byte array mem. The 8 bytes that are at position pos are overwritten. The byte ordering is decided by the value of the byteorder parameter:

Value Platform Byte ordering
GE_MOTOROLA Motorola big endian
GE_INTEL Intel little endian

An IEE double float consists of 1 sign bit (0 = positive and 1 = negative), 11 bits for the exponent (unsigned but biased with 1023) and 52 bits for the mantissa (a binary fraction with an implied leading 1).

Remember: The first element of a byte array is at position 0.

Return Value

The function returns TRUE if the operation was successful. Otherwise it returns FALSE.

Example

// Outputs "Motorola: 1421826.5912 => 4135B202A0000000
//          Intel:    1421826.5912 => 000000A002B23541".

var mem = new(bytes,8);
var x = 1421826.5912;

// Motorola
liee2mem(x,mem,0,GE_MOTOROLA);
println("Motorola: 1421826.5912 => ",tostring(mem[0],"02X"),
                                     tostring(mem[1],"02X"),
                                     tostring(mem[2],"02X"),
                                     tostring(mem[3],"02X"),
                                     tostring(mem[4],"02X"),
                                     tostring(mem[5],"02X"),
                                     tostring(mem[6],"02X"),
                                     tostring(mem[7],"02X"));

// Intel
liee2mem(x,mem,0,GE_INTEL);
println("Intel:    1421826.5912 => ",tostring(mem[0],"02X"),
                                     tostring(mem[1],"02X"),
                                     tostring(mem[2],"02X"),
                                     tostring(mem[3],"02X"),
                                     tostring(mem[4],"02X"),
                                     tostring(mem[5],"02X"),
                                     tostring(mem[6],"02X"),
                                     tostring(mem[7],"02X"));

See Also

[bytes], mem2word(), mem2uword(), mem2long(), mem2iee(), mem2liee(), word2mem(), uword2mem(), long2mem(), iee2mem(),