Trying to figure out the binary representation of a boolean in @rustlang. Is it machine dependent? Is it anything that's non-zero? Is there some way to print it? `println!("{:08b}", true);` fails
-
-
Thanks for the reply! So is it safe to say then that it's always 0b0000_0001 for true and 0b0000_0000 for false?
-
Yes. `unsafe` code could in theory create a `bool` with a different value, but that is immediate undefined behavior. Regarding printing: `println!("{:08}", true as u8)` (i.e. cast to u8 before printing).
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.