iostream.swap4
Defined in module
"iostream"from "iostream" import swap4Byte-swaps a 32-bit value
Parameters
val | number | the value whose low 32 bits get byte-swapped |
Return value
An int in [0, 4294967295]: the four low bytes of val, in reverse order.
Notes
Only the low 32 bits of val matter; higher bits are discarded, not carried into the result. Swapping is its own inverse, so swap4(swap4(val) & 0xFFFFFFFF) restores the original low 32 bits.
Example
from "iostream" import swap4
println("swap4(0x11223344) =", swap4(0x11223344))
println("swap4(swap4(0x11223344)) =", swap4(swap4(0x11223344))) // swapping twice restores the value
// only the low 32 bits count; the discarded high bits do not come back
println("swap4(0x100000000 + 0x11223344) == swap4(0x11223344) =", swap4(0x100000000 + 0x11223344) == swap4(0x11223344))Output:
swap4(0x11223344) = 1144201745
swap4(swap4(0x11223344)) = 287454020
swap4(0x100000000 + 0x11223344) == swap4(0x11223344) = trueSee also
swap2 | Byte-swaps a 16-bit value |
swap4 | Byte-swaps the blob contents as an array of 32-bit values |
casti2f | Reinterprets the bits of an integer as a float |
| iostream | module index |