Main Content

bitsra

Bit shift right arithmetic

Description

example

c=bitsra(a,k) returns the result of an arithmetic right shift by k bits on input a for fixed-point operations. For floating-point operations, it performs a multiply by 2-k.

If the input is unsigned, bitsra shifts zeros into the positions of bits that it shifts right. If the input is signed, bitsra shifts the most significant bit (MSB) into the positions of bits that it shifts right.

bitsra ignores fimath properties such as RoundingMode and OverflowAction.

When a is a fi object, a and c have the same associated fimath and numerictype objects.

Examples

collapse all

Create a signed fixed-point fi object with a value of –8, word length 4, and fraction length 0. Then display the binary value of the object.

a = fi(-8,1,4,0);
disp(bin(a))
1000

Shift a right by 1 bit.

disp(bin(bitsra(a,1)))
1100

bitsra shifts the MSB into the position of the bit that it shifts right.

Use bitsra to shift an int8 input right by 2 bits.

a = int8(64);
bitsra(a,2)
ans = int8
    16

Shift right a built-in int8 input using a fi shift value.

k = fi(2);
a = int8(64);
bitsra(a,k)
ans = int8
    16

Scale a floating-point double input by 2-3.

a = double(128);
bitsra(a,3)
ans = 16

Input Arguments

collapse all

Data that you want to shift, specified as a scalar, vector, matrix, or multidimensional array of fi objects or built-in numeric types.

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

Complex Number Support: Yes

Number of bits to shift, specified as a non-negative integer-valued scalar fi object or built-in numeric type.

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

Extended Capabilities

Version History

Introduced in R2007b

See Also

| | |