(So far, 104 people got it right out of 299 for a success rate of 34%)

According to ANSI-C, which of the following literal integer representations will give a compiler error?
Pick one:
uint8_t x = 0b101010;
uint8_t x = 42;
uint8_t x = 0x2A;
uint8_t x = 052;
None of the above. They will all compile successfully under ANSI-C

[ - ]
Comment by tcfkatDecember 14, 2022


CC5X (for the Microchip MCUs) compiles binary literals without problems.

SDCC V4.2.0 (for different 8 Bit MCUs) compiles also without problems. If I use the --std-c11 switch it complains: warning 261: binary integer constant requires C23 or later

If I use the --std-c2x switch it compiles without warnings.

So, binary literals are also included in the C standard?

Best regards,


[ - ]
Comment by p_v_sDecember 14, 2022

Nice question again!

I learned that it does not make a difference if the case of 0x matches the (upper/lower)case of the hex literals after it.

> As an aside, the 052 is an octal number. You can learn a bit more about octals here, although they are 
> rarely, if ever used in embedded systems.

Unless your "embedded system" is a PDP-8.

[ - ]
Comment by whygeeMay 19, 2023

Early Cray machines were naturally octal, as well :-)

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: