Mojo function
byte_swap
byte_swap(val: Int) -> Int
Byte-swaps an integer value with an even number of bytes.
Byte swap an integer value (8 bytes) with an even number of bytes (positive multiple of 16 bits). This returns an integer value (8 bytes) that has its bytes swapped. For example, if the input bytes are numbered 0, 1, 2, 3, 4, 5, 6, 7 then the returned integer will have its bytes in 7, 6, 5, 4, 3, 2, 1, 0 order.
Args:
- βval (
Int
): The input value.
Returns:
The input value with its bytes swapped.
byte_swap[type: DType, width: Int, //](val: SIMD[type, width]) -> SIMD[$0, $1]
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 with an even number of bytes (Bitwidth % 16 == 0).
Parameters:
- βtype (
DType
):dtype
used for the computation. - βwidth (
Int
): SIMD width used for the computation.
Args:
- βval (
SIMD[type, width]
): The input value.
Returns:
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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?