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

1.6 Converting Binary Numbers into Decimal

1.6 Converting Binary Numbers into Decimal

To convert a binary number into decimal, write the number as the sum of the powers of 2.

Example 1.1

Convert binary number 10112 into decimal.

Solution 1.1

Write the number as the sum of the powers of 2:

10112 = 1 ? 23 + 0 ? 22 + 1 ? 21 + 1 ? 20

     = 8 + 0 + 2 = 1

     = 11

or, 10112 = 1110

Example 1.2

Convert binary number 110011102 into decimal.

Solution 1.2

Write the number as the sum of the powers of 2:

110011102 = 1 ? 27 + 1 ? 26 + 0 ? 25 + 0 ? 2+ 1 ? 23 + 1 ? 22 + 1 ? 21 + 0 ? 20

     = 128 + 64 + 0 + 0 + 8 + 4 + 2 + 0

     = 206

or, 110011102 = 20610

Table 1.1 shows the decimal equivalent of numbers from 0 to 31.

Table 1.1: Decimal equivalent of binary numbers

Binary Decimal Binary Decimal
00000000 0 00010000 16
00000001 1 00010001 17
00000010 2 00010010 18
00000011 3 00010011 19
00000100 4 00010100 20
00000101 5 00010101 21
00000110 6 00010110 22
00000111 7 00010111 23
00001000 8 00011000 24
00001001 9 00011001 25
00001010 10 00011010 26
00001011 11 00011011 27
00001100 12 00011100 28
00001101 13 00011101 29
00001110 14 00011110 30
00001111 15 00011111 31

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


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