In reality, we often express long binary numbers in the form of 0000 1111 0011 1100 to make reading easier. And very often, especially in dealing with chip-chip communications in embedded systems (like I2C), we have to perform bitwise logical operations (usually bitwise OR) to abstract informations for decisions.
Yet as far as I know, in the C standard, no spacing or any form of separation between digits is allowed, which makes it more difficult to read the long binary numbers. Using hexadecimal number is somehow worse since it masks the binary number.
Is there a conforming way to express long binary numbers with separators (such as 0b0000 1111 0011 1100) in C?
Yes, with the newly released C standard (C23), you can use ' as a digit separator:
uint16_t x = 0b0000'1111'0011'1100;
Digit separators are ignored when determining the value of the constant.
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