MATLAB: [bug] boolean to uint8

2016acastMATLABnot a bugnot typecast

To my knowledge, matlab is the only coding language on the planet cannot convert a boolean to a byte.
typecast(boolean(0),'uint8')
or
typecast(logical(0),'uint8')
yields:
Error using typecast
The first input argument must be a full, non-complex numeric value.
Granted, there are easy hack-a-rounds to get past this but its frustrating to have to use them. I am using 2016A. Will/has matlab ever addressed this?

Best Answer

No, MATLAB is not going to address this. typecast() involves re-interpreting representation, but MATLAB does not publicly define the representation of logical (or boolean). As far as the user is concerned, a vector of logical values might be internally implemented as a packed array of bits, or might be implemented as bytes where 0 is false and all-ones is true, or where 0 is false and true has only the top bit set in the byte, or by some other method.
MATLAB also does not permit typecast between numeric values and char. This ambiguity allowed them to move from 8 bit characters to 16 bit characters without change to the user interface; at some point Mathworks might switch to 32 bit characters to permit full Unicode.
Historically, PASCAL did not offer any typecast operation, and logical values were an enumerated type. In the implementation I programmed in (decades ago), logical true was internally represented as a byte of all 1's, because the processor family we were using (Motorola MC68020) was one cycle faster at Test For Negative than it was for Test For Non Zero.
Related Question