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

1.17 Adding Binary Numbers

1.17 Adding Binary Numbers

The addition of binary numbers is similar to the addition of decimal numbers. Numbers in each column are added together with a possible carry from a previous column. The primitive addition operations are:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10     generate a carry bit
1 + 1 + 1 = 11 generate a carry bit

Some examples follow.

Example 1.24

Find the sum of binary numbers 011 and 110.

Solution 1.24

We can add these numbers as in the addition of decimal numbers:

  011 First column: 1 + 0 + 1

+ 110 Second column: 1 + 1 = 0 and a carry bit

 -––– Third column: 1 + 1 = 10

 1001

Example 1.25

Find the sum of binary numbers 01000011 and 00100010.

Solution 1.25

We can add these numbers as in the addition of decimal numbers:

  01000011 First column: 1 + 0 + 1

+ 00100010 Second column: 1 + 1 = 10

  –––––––– Third column: 0 + carry = 1

  01100101 Fourth column: 0 + 0 = 0

Fifth column: 0 + 0 = 0

Sixth column: 0 + 1 = 1

Seventh column: 1 + 0 = 1

Eighth column: 0 + 0 = 0

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


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