Binary constants


Binary constants can be written in a C source program.

[Function]

-

A binary constant can be written at a location where integer constants can be written.

[Effect]

-

When writing a constant in a bit string, a binary constant can be directly written without being converted into an octal or hexadecimal constant and the readability is improved.

[Usage]

-

A binary constant is written in the following manner.

0b    Binary constant
0B    Binary constant

-

After 0b or 0B, write a sequence of numbers 0 and 1.

-

One "_" can be written between numbers.

-

The value of a binary constant is calculated with 2 as the radix.

-

The type of a binary constant is the same as an octal or hexadecimal constant.

[Example]

The following shows a sample C source code.

int i1, i2, i3;
 
i1 = 0b00101100;
i2 = 0b0001_1000;
i3 = 0B0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1

 

The object code output by the compiler becomes the same as shown below.

int i1, i2, i3;
 
i1 = 0x2c;
i2 = 0x18;
i3 = 0x5555;