Bit_Operations module

byte_swap

procedureSource

Reverses the byte order of input and returns the result; input is untouched.

Works on the bytes of any type, so u16, s32, u64 and plain structs are swapped the same way (the whole value is reversed, not each field). Swapping twice gives the original value back.

Example↗
assert(byte_swap(cast(u32) 0x11223344) == 0x44332211);
assert(byte_swap(cast(u16) 0x00ff) == 0xff00);
assert(byte_swap(byte_swap(cast(u64) 0x0102030405060708)) == 0x0102030405060708);
byte_swap :: (input: $T) -> T

Parameters

input: $T

Returns

T

See also