MDME: MANUFACTURING, DESIGN, MECHANICAL ENGINEERING

# BINARY NUMBERS

Binary numbers and other bases

Smartboard Notes:

#### The Binary System

Binary System or base 2 system is a numerical system that represents values using two symbols 0 and 1. The binary system is used internally by all modern computers.

Since binary is a base 2 system each digit represents an increasing power of 2, with the right most digit 20 , the next 21, then 22, and so on.

 Power of 2 27 26 25 24 23 22 21 20 Value 128 64 32 16 8 4 2 1

Example:

The binary number 1 0 0 1 0 1 is converted to decimal form by

(1 x 25 ) + (0 x 24 ) + (0 x 23 ) + (1 x 22 ) + (0 x 21 ) + (1 x 20 )

= 32 + 0 + 0 + 4 + 0 + 1

= 37

Counting up in binary..

 Decimal Binary 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 11 1011 12 1100

etc..

#### Binary to Decimal

What does the binary number (1 0 0 1 0 1 0)2 represent in the decimal system?

(Note, the subscript 2 tells you the BASE of the number. i.e. Base 2, also known as BINARY)

 Power of 2 27 26 25 24 23 22 21 20 Value 128 64 32 16 8 4 2 1 Binary Number 1 0 0 1 0 1 0 64 8 2

= 64+8+2 = 74

Or

(64 x 1) + (32 x 0) + (16 x 0) + (8 x 1) + (4 x 0) + (2 x 1) + (1 x 0) = 74

Note: even numbers always finish with a 0, odd numbers finish with a 1.

#### Decimal to Binary

How would we convert 7410 to binary? (The subscript is 10, or base 10, known as decimal, which is a normal number)

Divide the number by 2 and record the remainder. Keep dividing the number by 2. Then read the remainder backwards!

 number/2 remainder 74/2 = 37 0 37/2 = 18 1 18/2 = 9 0 9/2 = 4 1 4/2 = 2 0 2/2 = 1 0 1/2 = 0 1

Thus 7410 = 10010102

Convert the following decimal numbers to binary:

(a) 9310

(b) 5610

(c) 4510

Convert the following binary to decimal

(d) (1111)2

(e) (1001101)2

(f) (1001101)2

9310 = (1011101)2

5610 = (111000)2

4510 = (101101)2

(1111)2 = 1510

(1001101)2 = 7710

(1001101)2 = 9910

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 10

 No 1 (a) 1 1 1 (b) 1 0 1 (c) 1 1 1 No 2 1 1 0 1 1 1 1 1 1 Total 1 1 0 1 1 1 0 0 1 1 1 0 Carry 1 1 1 1 1

#### Binary Multiplication

(Very similar to the decimal system)

1 x 1 = 1

1 x 0 = 0

0 x 1 = 0

Multiply the following

 No 1 (a) 1 0 1 0 (b) 1 0 0 0 (c) 1 0 1 0 No 2 1 1 1 1 1 1 1 1 Digit 1 1 0 1 0 1 0 0 0 1 0 1 0 Digit 2 1 0 1 0 1 0 0 0 1 0 1 0 Digit 3 1 0 0 0 1 0 1 0 Total 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 1 1 0 Carry 1 1

#### Binary Subtraction

0 - 0 = 0

0 - 1 = 1 borrow 1

1 - 0 = 1

1 - 1 = 0

When subtracting a 1 digit from a 0 produces the 1 digit but 1 must be subtracted from the next column. This is known as borrowing.

Examples

 No 1 (a) 1 1 0 1 1 1 0 (b) 1 1 1 1 (c) 1 1 1 1 1 (d) 1 0 0 1 1 No 2 1 0 1 1 1 1 0 1 0 1 0 0 1 1 0 1 Answer 1 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 1 1 1 0 Borrow 1 1 1 1 1 1 1

Every answer can be checked by converting the binary number to a decimal number.

For example in (d), converted to decimal the question is 19 - 5 = 14.

#### Binary Division

(this is similar to decimal division)

In decimal 54 / 3 = 18

 1 8 3 ) 5 4 3 2 4 2 4 0 0

27 / 5 = 5 remainder 2

 0 5 5 ) 2 7 0 2 7 2 5 2

Binary of 27 / 5...

 1 0 1 1 0 1 ) 1 1 0 1 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0

In decimal this problem is 27 / 5 = 5 remainder 2

In binary it is (1 1 0 1 1)2 / (1 0 1)2 = (1 0 1)2 remainder (1 0)2

What does (1 0 0 1 1 1)2 / (1 0 0)2 equal ?

Another numbering system is the Hexadecimal system which is base 16 system. In the decimal system (base 10) ten digits are used

0 1 2 3 4 5 6 7 8 9 in the Hexadecimal system as well as the ten digits used in the decimal system the following letters are used A, B, C, D, E, and F.

 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

Sometimes a hexadecimal number can look like a decimal number when there are no letters used.

Converting Hexadecimal to decimal is easy - simply multiply the digit in each column by that power of 16. Notice that the hexadecimal numbers are more powerful than decimal numbers, so it takes less digits for the same number.

 Power of 16 164 163 162 161 160 Value 65536 4096 256 16 1

Converting the other way, Decimal to Hexadecimal is done exactly the same way as in binary. We keep dividing the number and recording the remainder, then read the remainder backwards.

How to convert a decimal number to hexadecimal number:

1. Divide the decimal number by 16. (treat the division as an integer division).

2. Write down the remainder (in hexadecimal, ie if the number is 12, write down "C").

3. Repeat steps 1 and 2 until the remainder is less than 16.

4. The hexadecimal answer is the sequence of remainders in reverse order.

Convert decimal 188 to hex

 Division Integer Remainder 188/16 11 C 11/16 0 B

So 18810 = BC16

Convert 92110 to hex

 Division Integer Remainder 921/16 57 9 57/16 3 9 3/16 0 3

So 92110 = 39916

Convert 1128 10 to hex

 Division Integer Remainder 1128/16 70 8 70/16 4 6 4/16 0 4

So 112810 = 46816

Exercises

Convert the binary numbers into decimal numbers

(a) (1111101)2

(b) (110101)2

Convert the decimal numbers into binary numbers

(a) (225)10

(b) (731)10

(a) (11101)2 + (10001)2

(b) (111111)2 + (11011)2

Subtract the following binary numbers

(a) (11111)2 - (10011)2

(b) (10011)2 - (1110)2

Multiply the following binary numbers

(a) (1111)2 x (1001)2

(b) (101010)2 x (1101)2

Divide the following binary numbers

(a) (111101)2 / (101)2

(b) (11010)2 / (111)2

Convert the following decimal numbers into hexadecimal

(a) (245)10

(b) (789)10

#### Questions:

Assignment: Do all questions