Main Index : Reference :

long2mem()


Description

Converts an integer variable into a 32 bit signed long int and inserts it at a certain position in a byte array.

Definition

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

Parameters

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

Function

long2mem() converts value into a 32 bit signed long int and inserts it at the position pos in the byte array mem. The 4 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

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: 18265912 => 01160138
//          Intel:    18265912 => 38B71601".

var mem = new(bytes,4);
var x = 18265912;

// Motorola
long2mem(x,mem,0,GE_MOTOROLA);
println("Motorola: 18265912 => ",tostring(mem[0],"02X"),
                                 tostring(mem[1],"02X"),
                                 tostring(mem[2],"02X"),
                                 tostring(mem[3],"02X"));

// Intel
long2mem(x,mem,0,GE_INTEL);
println("Intel:    18265912 => ",tostring(mem[0],"02X"),
                                 tostring(mem[1],"02X"),
                                 tostring(mem[2],"02X"),
                                 tostring(mem[3],"02X"));

See Also

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