ror!(B::BitArray{1}, i::Integer)

ror!(B::BitArray{1}, i::Integer) -> BitArray{1}

Performs a right rotation operation on B.

Examples

  1. 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
    1

    This example performs a right rotation of src by 2 positions and stores the result in dest.

  2. 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
    0

    It demonstrates the right rotation of a BitArray with a different length.

  3. 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
    1

    It 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.

*Required Field
Details

Checking you are not a robot: