Main Index : Reference :
[bool] long2mem([int] value,[bytes] mem,[int] pos,[int] byteorder)
value is an integer.mem is a byte array.pos is the position within mem.byteorder is either big endian or little endian.
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.
TRUE if the operation was successful. Otherwise it returns FALSE.
// 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"));