Main Content

bitrol

Bitwise rotate left

Description

example

c = bitrol(a, k) returns the value of the fixed-point fi object, a, rotated left by k bits. bitrol rotates bits from the most significant bit (MSB) side into the least significant bit (LSB) side. It performs the rotate left operation on the stored integer bits of a.

bitrol does not check overflow or underflow. It ignores fimath properties such as RoundingMode and OverflowAction.

a and c have the same fimath and numerictype properties.

Examples

collapse all

Create an unsigned fixed-point fi object with a value of 10, word length 4, and fraction length 0.

a = fi(10,0,4,0);
disp(bin(a))
1010

Rotate a left 1 bit.

disp(bin(bitrol(a,1)))
0101

Rotate a left 2 bits.

disp(bin(bitrol(a,2)))
1010

Create a vector of fi objects.

a = fi([1,2,5,7],0,4,0)
a = 
     1     2     5     7

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 4
        FractionLength: 0
disp(bin(a))
0001   0010   0101   0111

Rotate the bits in vector a left 1 bit.

disp(bin(bitrol(a,1)))
0010   0100   1010   1110

Create an unsigned fixed-point fi object with a value 10, word length 4, and fraction length 0.

a = fi(10,0,4,0);
disp(bin(a))
1010

Rotate a left 1 bit where k is a fi object.

disp(bin(bitrol(a,fi(1))))
0101

Input Arguments

collapse all

Data that you want to rotate, specified as a scalar, vector, matrix, or multidimensional array of fi objects. a can be signed or unsigned.

Data Types: fixed-point fi

Complex Number Support: Yes

Number of bits to rotate, specified as a non-negative integer-valued scalar fi object or built-in numeric type. k can be greater than the word length of a. This value is always normalized to mod(a.WordLength,k).

Data Types: fi |single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2007b