Main Index : Reference :

mem2long()


Description

Converts a 32 bit signed long int at a certain position in a byte array into a C.O.F.F.E.E. integer.

Definition

[int] mem2long([bytes] mem,[int] pos,[int] byteorder)

Parameters

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

Return Value

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.

Example

// 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);

See Also

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