# Shift Arithmetic

Shift bits or binary point of signal

Libraries:
Simulink / Logic and Bit Operations
HDL Coder / Logic and Bit Operations

## Description

The Shift Arithmetic block can shift the bits or the binary point of an input signal, or both.

For example, shifting the binary point on an input of data type `sfix(8)` by two places to the right and left gives these decimal values.

Shift OperationBinary ValueDecimal Value

No shift (original number)

11001.011

–6.625

Binary point shift right by two places

1100101.1

–26.5

Binary point shift left by two places

110.01011

–1.65625

This block performs arithmetic bit shifts on signed numbers. Therefore, the block recycles the most significant bit for each bit shift. Shifting the bits on an input of data type `sfix(8)` by two places to the right and left gives these decimal values.

Shift OperationBinary ValueDecimal Value

No shift (original number)

11001.011

–6.625

Bit shift right by two places

11110.010

–1.75

Bit shift left by two places

00101.100

5.5

## Ports

### Input

expand all

Number to be operated on, specified as a scalar, vector, or array.

Data Types: `single` | `double` | `half` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

Number of bits to shift, specified as a scalar.

Data Types: `single` | `double` | `half` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

### Output

expand all

Result of operation, returned as a scalar, vector, or array.

Data Types: `single` | `double` | `half` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

## Parameters

expand all

Specify whether to enter the bits to shift on the dialog box or to inherit the values from an input port.

Tunable: No

#### Programmatic Use

 Block Parameter: `BitShiftNumberSource` Type: character vector, string Values: `'Dialog'` | ```'Input port'``` Default: `'Dialog'`

Specify a scalar, vector, or array of bit shift values. This parameter is available when Bits to shift: Source is `Dialog`.

If the direction is...Then...
`Left` or `Right` Use positive integers to specify bit shifts.
`Bidirectional` Use positive integers for right shifts and negative integers for left shifts.

Tunable: No

#### Programmatic Use

 Block Parameter: `BitShiftNumber` Type: character vector, string Values: `scalar` Default: `'9'`

Specify the direction in which to shift bits: left, right, or bidirectional.

Tunable: No

#### Programmatic Use

 Block Parameter: `BitShiftDirection` Type: character vector, string Values: `'Left'` | `'Right'` | `'Bidrectional'` Default: `'Bidrectional'`

Specify an integer number of places to shift the binary point of the input signal. A positive value indicates a right shift, while a negative value indicates a left shift.

Tunable: No

#### Programmatic Use

 Block Parameter: `BinPtShiftNumber` Type: character vector, string Values: `'Dialog'` | ```'Input port'``` Default: `'Dialog'`

Specify whether to produce a warning or error during simulation when the block contains an out-of-range shift value. Options include:

• `None` — Simulink® takes no action.

• `Warning` — Simulink displays a warning and continues the simulation.

• `Error` — Simulink terminates the simulation and displays an error.

For more information, see Simulation and Accelerator Mode Results for Out-of-Range Bit Shift Values.

#### Programmatic Use

 Block Parameter: `DiagnosticForOORShift` Type: character vector, string Values: `'None'` | `'Warning'` | `'Error'` Default: `'None'`

Select this check box to include conditional statements in the generated code that protect against out-of-range bit shift values. This check box is available when Bits to shift: Source is `Input port`.

For more information, see Code Generation for Out-of-Range Bit Shift Values.

#### Programmatic Use

 Block Parameter: `CheckOORBitShift` Type: character vector, string Values: `'on'` | `'off'` Default: `'off'`

## Block Characteristics

 Data Types `double` | `fixed point` | `half` | `integer` | `single` Direct Feedthrough `yes` Multidimensional Signals `no` Variable-Size Signals `no` Zero-Crossing Detection `no`

expand all

expand all

## Version History

Introduced before R2006a