Swaps the byte order of a 32-bit integer
Device + Agent
Name | Type | Description |
---|---|---|
value | Integer |
Any numerical value
|
Integer
This function takes an 32-bit integer and reverses the byte order: bytes 1, 2, 3 and 4 become bytes 4, 3, 2 and 1, converting it from big-endian to little-endian representation, or vice versa. The following diagram shows where bytes start out and where they end up; the numbers shown are each byte’s index in the initial sequence:
For example:
local a = 0x1A2B3C4D;
server.log(format("Before swap4(): 0x%X", a));
server.log(format(" After swap4(): 0x%X", swap4(a)));
logs:
2019-02-18 10:01:34.067 +00:00 "imp004m-BB-1": [Agent] Before swap4(): 0x1A2B3C4D
2019-02-18 10:01:34.068 +00:00 "imp004m-BB-1": [Agent] After swap4(): 0x4D3C2B1A
Do not confuse this function with the blob library’s blob.swap4() method, which works on a target blob object not an integer parameter.