FAQ: Why aren't boolean and 1 bit unsigned integers treated as the same data type?
10 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Fixed Point Team
2020 年 11 月 2 日
編集済み: Andy Bartlett
2020 年 11 月 2 日
Variables and signals of the boolean data type (called logical in MATLAB) only represent the values 0 and 1.
Variables and signals that are 1 bit unsigned integers also represent only the values 0 and 1.
Furthermore, variables and signals of both types can be represented on ASICs and FPGAs with just one bit.
So why aren't these treated as the same data type?
0 件のコメント
採用された回答
Andy Bartlett
2020 年 11 月 2 日
編集済み: Andy Bartlett
2020 年 11 月 2 日
Casting a numeric data type to boolean data type is very different from casting to any other numeric type. The following figure shows that casting to boolean behaves very differently from cast to an unsiged 1 bit integer. This difference in behavior when casting to the type is the fundamental reason why boolean and 1 bit unsigned are not the same data type.
Figure: Casting values -5:0.25:5 to boolean and to 1 bit unsigned with saturation and wrapping.
For full details of this example, see the attached pdf. Or, read the quick recap below.
The top plot in the figure shows cast to boolean. The output is always 1 except for the one case when the input is 0.
The middle plot shows a saturating cast to 1 bit unsigned integer. The plot is a step function with an output sequence of all 0s followed by a sequence of all 1s. Clearly, this behaves very differently from cast to boolean.
The bottom plot shows a wrapping cast to 1 bit unsigned integer. The plot is periodic with period two. The first half of a period is all 0s, and the second half is all 1s. Clearly, this behaves very differently from cast to boolean.
-Andy
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で FPGA, ASIC, and SoC Development についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!