For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
byte_swap
def byte_swap[dtype: DType, width: SIMDLength, //](val: SIMD[dtype, width]) -> SIMD[dtype, width]
Byte-swaps a SIMD vector of integer values with an even number of bytes.
Byte swap an integer value or vector of integer values with an even number of bytes (positive multiple of 16 bits). For example, The Int16 returns an Int16 value that has the high and low byte of the input Int16 swapped. Similarly, Int32 returns an Int32 value that has the four bytes of the input Int32 swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned Int32 will have its bytes in 3, 2, 1, 0 order. Int64 and other integer type extend this concept to additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Constraints:
The element type of the input vector must be an integral type.
Parameters:
- dtype (
DType):dtypeused for the computation. - width (
SIMDLength): SIMD width used for the computation.
Args:
- val (
SIMD[dtype, width]): The input value.
Returns:
SIMD[dtype, width]: A SIMD value where the element at position i is the value of the
element at position i of the input value with its bytes swapped.