在本演示中,我们将介绍如何使用程序块Extract Bits
,它允许您提取输入数字指定位置上的位。
在设计数字通信系统算法、为控制系统或机器人技术中的位信号线建模以及执行各种图形编程任务时,该程序块非常有用。
程序块Extract Bits
将一个整数作为输入,并从中生成一个新数字作为输出。在程序块属性中,您可以指定输入数字的哪些位将被复制,哪些位不会被复制。
在示例中,我们将向Extract Bits
模块的输入端输入一个UInt8
类型的常量,其值为 255。这个八位数的所有位均为 1。下面我们来展示程序块Extract Bits
的两种运行模式:
*Preserve fixed-point scaling
- 在数据类型转换过程中,输入数据的定点缩放用于确定输出缩放。
*Treat bit field as an integer
- 忽略输入数据的定点缩放,仅使用存储的整数计算输出数据类型。
extract_bits_treat_bit_fields_as_integer
模型演示了提取的比特序列成为块输出信号中低阶比特的运行模式。
从数字 255 中提取高两位后得到的信号MSB
将等于0b11
(数字 3),因为位序列11
被移到了低位。
extract_bits_preserve_fixed_point_scaling
机型演示了另一种块操作模式。在这种模式下,被选中的比特序列将保留在数字的数位网格中,其他位置则由 0 代替。我们可以说,通过这种方式,程序块实现了数字中的位屏蔽。
现在,MSB 信号将等于0b11000000
,即 192。
Out[0]:
Dict{String, DataFrame} with 4 entries:
"Mid SB" => 1×2 DataFrame…
"LSB" => 1×2 DataFrame…
"MSB" => 1×2 DataFrame…
"Input" => 1×2 DataFrame…
我们可以看到在不同的块设置下,对位网格的高位、中位和低位进行采样时的位序列。
我们已经演示了Extract Bits
程序块如何与Integer To Bit Conversion
结合使用。因此,我们展示了屏蔽整数的工作原理,以及如何通过将整数组成一个新的短序列,在输出端只获取选定的比特。
与Bus
和Mux
一样,这是另一种可以通过一条信号线发送多个信号的方法。当然,这并不是该程序块的唯一或主要应用。
{"id": "8b8cfc17-d6a2-496b-9b01-718130c25e95", "data": [{"showlegend": true, "mode": "markers", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1, 1, 1, 1, 1, 1, 1], "type": "scatter", "x": [1, 2, 3, 4, 5, 6, 7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 8, "currentCount": 8}}}, {"showlegend": true, "mode": "markers", "xaxis": "x2", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y2", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1, 1, 1, 1, 1, 1, 1], "type": "scatter", "x": [1, 2, 3, 4, 5, 6, 7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 8, "currentCount": 8}}}, {"showlegend": true, "mode": "markers", "xaxis": "x3", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y3", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1], "type": "scatter", "x": [1, 2], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 2, "currentCount": 2}}}, {"showlegend": true, "mode": "markers", "xaxis": "x4", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y4", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1], "type": "scatter", "x": [7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 2, "currentCount": 2}}}, {"showlegend": true, "mode": "markers", "xaxis": "x5", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y5", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1, 1], "type": "scatter", "x": [3, 4, 5], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 3, "currentCount": 3}}}, {"showlegend": true, "mode": "markers", "xaxis": "x6", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y6", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1, 1], "type": "scatter", "x": [6, 7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 3, "currentCount": 3}}}, {"showlegend": true, "mode": "markers", "xaxis": "x7", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y7", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1], "type": "scatter", "x": [7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 2, "currentCount": 2}}}, {"showlegend": true, "mode": "markers", "xaxis": "x8", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y8", "legendgroup": "y1", "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1, 1], "type": "scatter", "x": [7, 8], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 2, "currentCount": 2}}}], "config": {"paper_bgcolor": "rgba(255, 255, 255, 1.000)", "xaxis7": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.07646908719743364, 0.5061698016914553], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y7", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "xaxis8": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.5637376057159522, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y8", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "height": 400, "yaxis4": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.5219952974628171, 0.7167199803149606], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x4", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "yaxis2": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.7641827974628171, 0.9589074803149606], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x2", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "xaxis3": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.07646908719743364, 0.5061698016914553], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y3", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "xaxis4": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.5637376057159522, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y4", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "annotations": [{"yanchor": "top", "xanchor": "center", "rotation": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 13}, "yref": "paper", "showarrow": false, "text": "Preserve fixed point scaling<br>(маскирование)", "xref": "paper", "x": 0.29131944444444446}, {"yanchor": "top", "xanchor": "center", "rotation": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 13}, "yref": "paper", "showarrow": false, "text": "Treat bit fields as integer<br>(выборка)", "xref": "paper", "x": 0.778587962962963}], "yaxis6": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.27980779746281703, 0.47453248031496054], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x6", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "xaxis5": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.07646908719743364, 0.5061698016914553], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y5", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "showlegend": false, "yaxis8": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.03762029746281702, 0.23234498031496048], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x8", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "yaxis3": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.5219952974628171, 0.7167199803149606], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x3", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "MSB", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "yaxis5": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.27980779746281703, 0.47453248031496054], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x5", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "Mid SB", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "yaxis7": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.03762029746281702, 0.23234498031496048], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x7", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "LSB", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "xaxis2": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.5637376057159522, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y2", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "xaxis6": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.5637376057159522, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y6", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "width": 1252.953125, "xaxis": {"showticklabels": true, "gridwidth": 0.5, "range": [0.79, 8.21], "domain": [0.07646908719743364, 0.5061698016914553], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "yaxis": {"showticklabels": true, "gridwidth": 0.5, "range": [0, 2], "domain": [0.7641827974628171, 0.9589074803149606], "mirror": false, "tickangle": 0, "showline": true, "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "Input", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}}}