Main Index : Reference :
[int] mem2long([bytes] mem,[int] pos,[int] byteorder)
mem is a byte array.pos is the position within mem.byteorder is either big endian or little endian.
mem2long() converts 4 bytes from position pos in the byte array mem as a 32 bit signed long int and returns the result as an integer value. 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.
// Outputs "0xF00B1201 = -267709951
// 0x01120BF0 = 17959920".
var mem = new(bytes,4);
mem[0] = 0xF0;
mem[1] = 0x0B;
mem[2] = 0x12;
mem[3] = 0x01;
var motorola = mem2long(mem,0,GE_MOTOROLA);
var intel = mem2long(mem,0,GE_INTEL);
println("0xF00B1201 = ",motorola);
println("0x01120BF0 = ",intel);