# bitsra

Bit shift right arithmetic

## Syntax

• ``c=bitsra(a,k)``
example

## 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

### Shift Right a Signed fi Input

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.

### Shift Right a Built-in int8 Input

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

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

### Shift Right Using a fi Shift Value

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

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

### Shift Right a Floating-Point Input

Scale a floating-point `double` input by .

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

## Input Arguments

collapse all

### `a` — Data that you want to shiftscalar | vector | matrix | multidimensional array

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

### `k` — Number of bits to shiftnon-negative integer-valued scalar

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`