I can't understand the following behavior.
I'm trying to declare byte mask using binary literal:
byte mask = 0b1111_1111;
But that's not possible, because I get the following error message:
Type mismatch: cannot convert from int to byte
The most interesting thing is that when I try to declare the mask directly, in decimal representation
byte mask = -1;
I get no error, but these two representations should be absolutely equal!
What am I doing wrong? Thanks in advance.
You can safely assign a values from -2^7 to 2^7-1 (-128 to 127)
to a byte
,since it is 8 bits.
where as 0b1111_1111
= 255
So need a cast there
byte mask = (byte) 0b1111_1111;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With