Skip to main content

blob.swap2()

Changes the order of the blob’s bytes

Availability

Device + Agent

Returns

Nothing

Description

This method changes the order of the contents of the target blob by reversing the order of every two bytes: bytes 0 and 1 become bytes 1 and 0, bytes 2 and 3 become bytes 3 and 2, and so on:

If each pair of bytes forms a 16-bit integer value, swap2() allows you change the ‘endian’ nature of this value: ie. whether its most-significant byte comes first or last. The imp is little-endian, but not all devices are, and this method allows you to interpret readings from them correctly, or to ensure that data sent to them is correctly formatted.

Example Code