C 소스의 모든 이진 표기법?

기술노트 46979






2018-02-28 오전 1:47


It is not possible to use binary notation (for example 0b01010101) in C-source when compiling with an IAR Systems compiler.


The notation 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 #define's.

All product names are trademarks or registered trademarks of their respective owners.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.