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

1.18 Subtracting Binary Numbers

1.18 Subtracting Binary Numbers

To subtract one binary number from another, convert the number to be subtracted into negative and then add the two numbers.

Example 1.26

Subtract binary number 0010 from 0110.

Solution 1.26

First, convert the number to be subtracted into negative:

0010 number to be subtracted

1101 complement

   1 add 1

––––
1110

Now add the two numbers:

  0110
+ 1110
  ––––
  0100

Since we are using only 4 bits, we cannot show the carry bit.

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


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