bswap
bswap(n)
Byte-swap an integer
Examples
In the Julia programming language, the function bswap(n) is used to byte-swap an integer n.
julia> bswap(0x12345678)
0x78563412
Here are some common examples of using the bswap function:
-
Byte swap an integer:
julia> bswap(12345) 48629This example byte-swaps the integer
12345resulting in48629. -
Byte swap a hexadecimal number:
julia> bswap(0xABCD) 0xCDABIt byte-swaps the hexadecimal number
0xABCDto0xCDAB. - Byte swap a negative number:
julia> bswap(-9876) -1124030976It byte-swaps the negative number
-9876resulting in-1124030976.
Common mistake example:
julia> bswap(3.14)
ERROR: MethodError: no method matching bswap(::Float64)
In this example, the bswap function expects an integer argument, but a floating-point number 3.14 is provided. Make sure to pass an integer to the bswap function to avoid such errors.
See Also
bitpack, bitunpack, bswap, flipbits!, htol, hton, isbits, ltoh, ntoh, rol, rol!, ror, ror!, signbit,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.