Output selection of contiguous bits from input signal
Logic and Bit Operations
The Extract Bits block allows you to output a contiguous selection of bits from the stored integer value of the input signal. Use the Bits to extract parameter to define the method for selecting the output bits.
Select Upper half
to output the
half of the input bits that contain the most significant bit. If there
is an odd number of bits in the input signal, the number of output
bits is given by the equation
number of output bits = ceil(number of input bits/2)
Select Lower half
to output the
half of the input bits that contain the least significant bit. If
there is an odd number of bits in the input signal, the number of
output bits is given by the equation
number of output bits = ceil(number of input bits/2)
Select Range starting with most significant
bit
to output a certain number of the most significant bits
of the input signal. Specify the number of most significant bits to
output in the Number of bits parameter.
Select Range ending with least significant
bit
to output a certain number of the least significant
bits of the input signal. Specify the number of least significant
bits to output in the Number of bits parameter.
Select Range of bits
to indicate
a series of contiguous bits of the input to output in the Bit
indices parameter. You indicate the range in [start
end]
format, and the indices of the input bits are labeled
contiguously starting at 0 for the least significant bit.
This block does not report wrap on overflow warnings during
simulation. To report these warnings, see the Simulink.restoreDiagnostic
reference
page. The block does report errors due to wrap on overflow.
The Extract Bits block accepts inputs of any numeric data type
that Simulink^{®} supports, including fixed-point data types. Floating-point
inputs are passed through the block unchanged. Boolean
inputs
are treated as uint8
signals.
Note: Performing bit operations on a signed integer is difficult. You can avoid difficulty by converting the data type of your input signals to unsigned integer types. |
For more information, see Data Types Supported by Simulink in the Simulink documentation.
Select the method for extracting bits from the input signal.
(Not shown on dialog above.) Select the number of bits to output from the input signal. Signed integer data types can have no less than two bits in them. Unsigned data integer types can be as short as a single bit.
This parameter is only visible if you select Range
starting with most significant bit
or Range ending
with least significant bit
for the Bits to extract parameter.
(Not shown on dialog above.) Specify a contiguous range of bits
of the input signal to output. Specify the range in [start
end]
format. The indices are assigned to the input bits
starting with 0 at the least significant bit.
This parameter is only visible if you select Range
of bits
for the Bits to extract parameter.
Select the scaling mode to use on the output bits selection:
When you select Preserve fixed-point scaling
,
the fixed-point scaling of the input is used to determine the output
scaling during the data type conversion.
When you select Treat bit field as an integer
,
the fixed-point scaling of the input is ignored, and only the stored
integer is used to compute the output data type.
Consider an input signal that is represented in binary by 110111001
:
If you select Upper half
for the Bits
to extract parameter, the output is 11011
in
binary.
If you select Lower half
for the Bits
to extract parameter, the output is 11001
in
binary.
If you select Range starting with most significant
bit
for the Bits to extract parameter,
and specify 3
for the Number of bits parameter,
the output is 110
in binary.
If you select Range ending with least significant
bit
for the Bits to extract parameter,
and specify 8
for the Number of bits parameter,
the output is 10111001
in binary.
If you select Range of bits
for
the Bits to extract parameter, and specify [4 7]
for the Bit indices parameter,
the output is 1011
in binary.
Data Types | Double | Single | Boolean | Base Integer | Fixed-Point |
Sample Time | Inherited |
Direct Feedthrough | Yes |
Multidimensional Signals | No |
Variable-Size Signals | No |
Zero-Crossing Detection | No |
Code Generation | Yes |