Main Index : Reference :

uword2mem()


Description

Converts an integer variable into a 16 bit unsigned short int word and inserts it at a certain position in a byte array.

Definition

[bool] uword2mem([int] value,[bytes] mem,[int] pos,[int] byteorder)

Parameters

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

Function

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.

Return Value

The function returns TRUE if the operation was successful. Otherwise it returns FALSE.

Example

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

See Also

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