ror!(B::BitArray{1}, i::Integer)
ror!(B::BitArray{1}, i::Integer) -> BitArray{1}
Performs a right rotation operation on B.
Examples
-
Perform a right rotation on a BitArray:
julia> src = BitArray([0, 1, 0, 1, 1]); julia> dest = similar(src); julia> ror!(dest, src, 2) 5-element BitArray{1}: 1 1 0 0 1This example performs a right rotation of
srcby 2 positions and stores the result indest. -
Rotate a BitArray with different length:
julia> src = BitArray([0, 1, 0, 1, 1, 0, 1]); julia> dest = similar(src); julia> ror!(dest, src, 4) 7-element BitArray{1}: 1 1 0 1 0 1 0It demonstrates the right rotation of a BitArray with a different length.
- Handle edge case with negative rotation:
julia> src = BitArray([1, 0, 1]); julia> dest = similar(src); julia> ror!(dest, src, -1) 3-element BitArray{1}: 0 1 1It handles negative rotations correctly and performs a right rotation in the opposite direction.
Common mistake example:
julia> src = BitArray([1, 0, 1]);
julia> dest = similar(src);
julia> ror!(dest, src, 5)
ERROR: BoundsError: attempt to access 3-element BitArray{1} at index [5]
In this example, the rotation index provided is out of bounds for the BitArray. Make sure to provide a valid index within the range of the BitArray to avoid such errors. Always verify that the index is within bounds before using ror!.
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.