- Tutorials
- Numerical Bases

I 1

II 2

III 3

IV 4

V 5

All the

1 I

10 X

100 C

In these cases, our symbol 1 does not have always a value of one (or I in Roman numbers). For example, in the second case, the symbol 1 represents a value of ten (or X in Roman) and in the third one, 1 represents a value of one hundred (or C).

For example:

200

+ 70

5

---

275

therefore, the first "2" sign is equivalent to 200 (2 x 100), the second "7" sign is equivalent to 70 (7 x 10) whereas the last sign corresponds to the value 5 (5 x 1).

This is because our system is a positional numeral system. Therefore, the value of a given digit depends on its position within the entire number being represented. All the above can be mathematically represented in a very simple way. For example, to represent the value 182736 we can assume that each digit is the product of itself multiplied by 10 powered to its place as exponent, beginning from the right with 10

the octals numbers include only the representations for the values from 0 to 7:

and, therefore, its mathematical base is 8. In C++ octal numbers are denoted by beginning always with a

octal decimal

----- -------

0 0 (zero)

01 1 (one)

02 2 (two)

03 3 (three)

04 4 (four)

05 5 (five)

06 6 (six)

07 7 (seven)

010 8 (eight)

011 9 (nine)

012 10 (ten)

013 11 (eleven)

014 12 (twelve)

015 13 (thirteen)

016 14 (fourteen)

017 15 (fifteen)

020 16 (sixteen)

021 17 (seventeen)

Thus, for example, the number 17 (seventeen, or XVII in Roman) it is expressed

therefore the octal number

hexadecimal decimal

----------- -------

0 0 (zero)

0x1 1 (one)

0x2 2 (two)

0x3 3 (three)

0x4 4 (four)

0x5 5 (five)

0x6 6 (six)

0x7 7 (seven)

0x8 8 (eight)

0x9 9 (nine)

0xA 10 (ten)

0xB 11 (eleven)

0xC 12 (twelve)

0xD 13 (thirteen)

0xE 14 (fourteen)

0xF 15 (fifteen)

0x10 16 (sixteen)

0x11 17 (seventeen)

In C++, hexadecimal numbers are preceded by

Once again we can use the same method to translate a number from a base to another one:

In order to translate it to decimal we would need to conduct a mathematical operation similar to the one we have used previously to convert from hexadecimal or octal, which would give us the decimal number 212628.

Nevertheless to pass this sequence to octal it will only take us some seconds and even the less skilled in mathematics can do it just by seeing it: Since 8 is 2

110 011 111 010 010 100

and now we just have to translate to octal numberal radix each group separately:

110 011 111 010 010 100

6 3 7 2 2 4

giving the number 637224 as result. This same process can be inversely performed to pass from octal to binary.

In order to conduct the operation with hexadecimal numbers we only have to perform the same process but separating the binary value in groups of 4 numbers, because 16 = 2

11 0011 1110 1001 0100

3 3 E 9 4

Therefore, the binary expression 110011111010010100 can be represented in C++ either as 212628 (decimal), as 0637224 (octal) or as 0x33e94 (hexadecimal).

The hexadecimal code is specially interesting in computer science since nowadays, computers are based on bytes composed of 8 binary bits and therefore each byte matches with the range that 2 hexadecimal numbers can represent. For that reason it is so frequently used to represent values translated to or from binary base.