Main Index : Reference :

word2mem()


Description

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

Definition

[bool] word2mem([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

word2mem() converts value into a 16 bit signed 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: 1524 => 05F4
//          Intel:    1524 => F405".

var mem = new(bytes,2);
var x = 1524;

// Motorola
word2mem(x,mem,0,GE_MOTOROLA);
println("Motorola: 1524 => ",tostring(mem[0],"02X"),
                             tostring(mem[1],"02X"));

// Intel
word2mem(x,mem,0,GE_INTEL);
println("Intel:    1524 => ",tostring(mem[0],"02X"),
                             tostring(mem[1],"02X"));

See Also

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