Main Index : Reference :
[int] mem2uword([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.
mem2uword() converts 2 bytes from position pos in the byte array mem as a 16 bit unsigned short int word 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 "0xF00B = 61451
// 0x0BF0 = 3056".
var mem = new(bytes,2);
mem[0] = 0xF0;
mem[1] = 0x0B;
var motorola = mem2uword(mem,0,GE_MOTOROLA);
var intel = mem2uword(mem,0,GE_INTEL);
println("0xF00B = ",motorola);
println("0x0BF0 = ",intel);