Numeric systems

Glossary > Numeric systems

We are used to specify integer numbers by 10 different digits. Computers however only  know 0 and 1. For example the number 156 of our decimal system expressed in the binary computer format is

10011100

Because such binary numbers can be transformed to octal and hexadecimal representations very easily, the c++ language has conventions for representing octal and hexadecimal values. Leading zeros are used to signal an octal constant and starting a number with "0x" indicates a hexadecimal constant.

The transformation of the binary value above into an octal number is done by separating the binary value in groups of 3 numbers and than replacing these group according to the table below:

10 011 100

2    3    4

In c++ the resulting octal number is written in c++ as: 0235

The procedure of converting the binary number into a hexadecimal representation is analogously, but you have to separate the digits into groups of four digits this time:

1001 1100

9      C

In c++ the resulting hexadecimal number is written in c++ as: 0x9C

Escape sequences are a similar representation of  characters by octal numbers or hexadecimal numbers.

 Binary Octal 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7

 Binary Hexadecimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F