# FAQ: Why aren't boolean and 1 bit unsigned integers treated as the same data type?

조회 수: 25(최근 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?

댓글을 달려면 로그인하십시오.

### 채택된 답변

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

댓글을 달려면 로그인하십시오.

### 범주

Find more on Logical in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by