Выбрать главу

Convert octal number 1778 into binary.

Solution 1.19

Write the binary equivalent of each octal digit:

1 = 0012 7 = 1112 7 = 1112

The binary number is 0011111112.

Example 1.20

Convert octal number 758 into binary.

Solution 1.20

Write the binary equivalent of each octal digit:

7 = 1112 5 = 1012

The binary number is 1111012.

1.15 Converting Binary Numbers into Octal

To convert a binary number into octal, arrange the number in groups of three and write the octal equivalent of each digit.

Example 1.21

Convert binary number 1101110012 into octal.

Solution 1.21

Arranging in groups of three:

110111001 = 110 111 001

             6   7   1

The octal number is 6718.

1.16 Negative Numbers

The most significant bit of a binary number is usually used as the sign bit. By convention, for positive numbers this bit is 0, and for negative numbers this bit is 1. Figure 1.5 shows the 4-bit positive and negative numbers. The largest positive and negative numbers are +7 and –8 respectively.

Binary number Decimal equivalent
0111 +7
0110 +6
0101 +5
0100 +4
0011 +3
0010 +2
0001 +1
0000 0
1111 −1
1110 −2
1101 −3
1100 −4
1011 −5
1010 −6
1001 −7
1000 −8

Figure 1.5: 4-bit positive and negative numbers

To convert a positive number to negative, take the complement of the number and add 1. This process is also called the 2’s complement of the number.

Example 1.22

Write decimal number −6 as a 4-bit number.

Solution 1.22

First, write the number as a positive number, then find the complement and add 1:

0110 +6

1001 complement

   1 add 1

−−−−

1010 which is −6

Example 1.23

Write decimal number −25 as a 8-bit number.

Solution 1.23

First, write the number as a positive number, then find the complement and add 1:

00011001 +25

11100110 complement

       1 add 1

–––––––-

11100111 which is −25

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.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.

1.19 Multiplication of Binary Numbers

Multiplication of two binary numbers is similar to the multiplication of two decimal numbers. The four possibilities are:

0 × 0 = 0

0 × 1 = 0

1 × 0 = 0

1 × 1 = 1

Some examples follow.

Example 1.27

Multiply the two binary numbers 0110 and 0010.

Solution 1.27

Multiplying the numbers:

   0110

   0010

   ----

   0000

  0110

 0000

0000

-------