BDE 4.14.0 Production release
|
Provide byte-order swapping functions.
This component provides a utility class
, bsls::ByteOrderUtil
, that contains a suite of static functions for reversing the byte order of integral types. The functions swapByteOrder{16,32,64}
reverse the byte order of words having the indicated widths (in bits), while the overloaded function swapBytes
will swap the bytes of any integral type passed to it, returning the same type it is passed.
In this example we demonstrate the use of different overloads of the swapBytes
function.
First we typedef
a shorthand to the namespace class
:
Then, we demonstrate reversing the bytes of an unsigned short
:
Next, we do a signed 'short:
Then, we reverse an unsigned int
:
Next, we reverse the bytes of a 32-bit signed integer:
Now, we perform the transform on a 64-bit unsigned:
Finally, we do a 64-bit signed integer: