Any binary notation in C-source?
Technical Note 46979
4/20/2016 11:27 AM
It is not possible to use binary notation (for example
0b01010101) in C-source when compiling with an IAR Systems compiler.
0b01010101 is not supported by the C-language (neither in C99 nor in C89). IAR Systems has not added any extension to support such notation. (Such an extension would make the C-source less portable.)
What to do
The solution is straight forward, as (for example) the binary value of 5 can be implemented as...
#define b0000000000000101 0x0005
...and such a
#define can be added for any binary value in use in the application.
In order to simplify, download this zip file. The zip file contains two files:
- Binary_values_8_bit.txt holds the defines for positive 8-bit binary values.
- Binary_values_16_bit.txt holds the defines for positive 16-bit binary values.
Please note that the text files are not header files from a C perspective. (The larger file holds over 64.000
#defines, which makes it very cumbersome.)
Instead copy the needed #define's from the text file and add them to a header file in your project. In this way you get no build time penalty because of unused
All product names are trademarks or registered trademarks of their respective owners.