Книга: Advanced PIC Microcontroller Projects in C

1.13 Converting Decimal Numbers into Octal

1.13 Converting Decimal Numbers into Octal

To convert a decimal number into octal, divide the number repeatedly by 8 and take the remainders. The first remainder is the LSD, and the last remainder is the MSD.

Example 1.17

Convert decimal number 15910 into octal.

Solution 1.17

Dividing the number repeatedly by 8:

159/8 ? 19 Remainder 7 (LSD)
19/8  ? 2  Remainder 3
2/8   ? 0  Remainder 2 (MSD)

The octal number is 2378.

Example 1.18

Convert decimal number 46010 into octal.

Solution 1.18

Dividing the number repeatedly by 8:

460/8 ? 57 Remainder 4 (LSD)
57/8  ? 7  Remainder 1
7/8   ? 0  Remainder 7 (MSD)

The octal number is 7148.

Table 1.3 shows the octal equivalent of decimal numbers 0 to 31.

Table 1.3: Octal equivalent of decimal numbers

Decimal Octal Decimal Octal
0 0 16 20
1 1 17 21
2 2 18 22
3 3 19 23
4 4 20 24
5 5 21 25
6 6 22 26
7 7 23 27
8 10 24 30
9 11 25 31
10 12 26 32
11 13 27 33
12 14 28 34
13 15 29 35
14 16 30 36
15 17 31 37

Оглавление книги


Генерация: 0.558. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз