Main Index : Reference :
[bool] uword2mem([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.
uword2mem() converts value into a 16 bit unsigned short int word and inserts it at the position pos in the byte array mem. The 2 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: 45524 => B1D4
// Intel: 45524 => D4B1".
var mem = new(bytes,2);
var x = 45524;
// Motorola
uword2mem(x,mem,0,GE_MOTOROLA);
println("Motorola: 45524 => ",tostring(mem[0],"02X"),
tostring(mem[1],"02X"));
// Intel
uword2mem(x,mem,0,GE_INTEL);
println("Intel: 45524 => ",tostring(mem[0],"02X"),
tostring(mem[1],"02X"));