Shift Arithmetic
Shift of bits or binary point of a signal.
Description
The Shift Arithmetic block can shift bits or a binary point of the input signal, or both.
The table shows an example of shifting the binary point for fixed
type input data by two digits to the right and left.
Shift operation | Binary value | Decimal value |
---|---|---|
Without shift (original number) |
11001.011 |
-6.625 |
Shifting the binary point to the right by two digits |
1100101.1 |
-26.5 |
Shift the binary point to the left by two digits |
110.01011 |
-1.65625 |
The Shift Arithmetic block performs a bit shift arithmetic operation on signed numbers. Therefore, the block reuses the high bit for each bit shift.
The table shows an example of bit shift for input data of fixed
type by two digits to the right and left.
Shift operation | Binary value | Decimal value |
---|---|---|
Unshifted (original number) |
11001.011 |
-6.625 |
Bit shift to the right by two digits |
11110.010 |
-1.75 |
Bit shift left by two digits |
00101.100 |
5.5 |
Ports
Input
u - converted number
scalar
| vector
| matrix
The number to perform a shift operation on, specified as a scalar, vector or matrix.
Data types: Float32
, Float64
, Int32
, Int64
, Fixed
.
s - number of bits to shift
scalar
The number of bits to shift, specified as a scalar.
Dependencies
To enable this port, set the Source parameter to Input port
.
Data types: Int32
, Int64
.
Parameters
Bits to shift
Source - source of number of bits to shift
Dialog (by default)
| Input port
Specify whether to enter the number of bits to shift in the dialogue box or inherit the values from the input port.
Block parameter |
|
Values |
|
By default |
|
Direction - bit shift direction
Bidirectional (by default)
| Right
| Left
Specify the bit shift direction: left, right or bidirectional.
Block parameter |
|
Values |
|
By default |
|
Number - number of bits to shift
8 (By default)
| scalar
Set the number of bits to shift.
If the Direction parameter is set to Bidirectional
, a positive Number value means shift to the right and a negative value means shift to the left.
Dependencies
This parameter is available if the Source parameter is set to Dialog
.
Block parameter |
|
Values |
|
By default |
|
Data types: Int32
, Int64
.
Main
Binary points to shift - number of digits to shift a binary point
0 (by default)
| scalar
Specify the integer number of digits to shift the binary point of the input signal. A positive number indicates a shift to the right, and a negative number indicates a shift to the left.
Block parameter |
|
Values |
|
By default |
|
Data types: Int32
, Int64
.
Diagnostic for out of range shift value - diagnostic action
None(By default)
| Error
Specify whether to output an error during simulation when a block contains an out of range shift value. Options include:
-
None
- the system takes no action. -
Error
- the system completes the simulation and displays an error.
Block parameter |
|
Values |
|
By default |
|
Read More
*Block icon variables
The Shift Arithmetic block icon* shows the behaviour of the block using these variables:
Qy
is the stored integer value of the output.
Qu
- stored integer input value.
Vy
- output value.
Vu
- input value.
Ey
- output degree value.
Eu
- input degree value.
*Block output for right bit shifts.
The example shows a comparison of the simulation results for right bit shifts for different values of the Source parameter: Dialog
and Input port
.
Parameter settings for the upper block Shift Arithmetic are given in the table.
Parameter | Value |
---|---|
Input port u |
|
Source |
|
*`Direction |
|
*`Number |
|
The upper block Shift Arithmetic takes 124
as input, which corresponds to 01111100
in binary format. Shifting the number of bits two bits to the right gives 00011111
in binary format. Hence, the block outputs 31
.
Parameter settings for the lower Shift Arithmetic block are given in the table.
Parameter | Value |
---|---|
Input port u |
|
Input port s |
|
*`Source |
`Input port |
*`Direction |
|
The Shift Arithmetic lower block performs the same operation as the upper block. However, the lower block receives the bit shift value through the input port instead of the Number parameter value. If the bit shift value is supplied through the input port as an input signal, the shift can be performed during simulation.
Output block for binary point shift
The following model shows the simulation of binary point shift.
Parameter settings for the upper block Shift Arithmetic are given in the table.
Parameter | Value |
---|---|
Input port u |
|
Source |
|
*`Direction |
|
*`Number |
|
*`Binary points to shift |
|
The upper block Shift Arithmetic takes 124.0
as input, which corresponds to 01111100
in binary format. Shifting the binary point three positions to the right gives 01111100000
in binary format. Hence, the upper block outputs 995.0
.
The parameter settings for the lower Shift Arithmetic block are given in the table.
Parameter | Value |
---|---|
Input port u |
|
Source |
|
*`Direction |
|
*`Number |
|
*`Binary points to shift |
|
The lower Shift Arithmetic block also takes 124.0
as input. Shifting the binary point three positions to the left gives 01111.100
in binary format. Hence, the lower block outputs 15.5
.
Algorithms
*Bit shift out of range
Assume that WL
is the length of the input machine word. The shaded areas in the following diagram show the bit shift out-of-range values for left and right shift.
Similarly, the shaded areas in the following diagram show the bit shift values outside the acceptable range for bidirectional shifts.
Depending on the Diagnostic for out of range shift value, the bit shift diagnostics for out of range shifts reacts as follows:
-
None
- the system does not take any action. -
Error
- the system completes the simulation and displays an error.
*Simulation and acceleration mode results for out-of-range bit shift values.
Assume that U
is the input value, WL
is the length of the input machine word and Y
is the output value. The output of the out-of-range bit shift value for left shifts is as follows:
Similarly, the output for the bit shift value outside the valid range for shifts to the right is as follows:
For bidirectional shifts, the output for a bit shift value outside the valid range is as follows: