Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Binary Numbers

# Binary Numbers

Ratings:

5.0

(1)
|Views: 2,638|Likes:

### Availability:

See more
See less

03/18/2014

pdf

text

original

1
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 1
Data Representation
\u2013 We have seen how various data (numbers, colours,
positions, letters) can be stored as binary numbers.
\u2013 Not all values that need to be stored are whole numbers.
(integers)
\u2013 Not all values that need to be stored are greater than zero.
(positive)
\u2013 Not all values can fit in 8-bit or 16-bit registers. (small
numbers)

\u2013 How does the computer store real numbers (fractions) ?
\u2013 How does the computer store negative numbers ?
\u2013 How does the computer store very large numbers ?

Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 2
Real Numbers
\u2013 Real Numbers are numbers with a fractional part.
102
101
100
10-1
10-2
10-3
3
1 .1
4
3
\u2013 Just as 31.143 can be constructed using negative powers of
10 (10-1 = 1/10+1 = .1), the same is true in binary
\u2022 Example:Convert 11.101 Binary to decimal
22
21
20
2-1
2-2
2-3
1
1 .1
0
1
= 2 + 1 + 1/21
+0
+ 1/23
= 3 + .5 + .0125
=3.512510 =11.1012
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 3
Binary Fractions
\u2013 Example: Convert 101.110012 to Decimal
First write down the powers of two (positive and negative).
22
21
20
2-1
2-2
2-3 2-4 2-5
1
0
1.. 1
1
0
0 1
= 4 + 1 + 1/21
+ 1/22 + 1/25
= 5 + .5 + .25 + .03125
=5.7812510 =101.110012
\u2013 Exercise:
\u2022 Convert 11.1001 to Decimal.
\u2022 Convert 1.10101 to Decimal.
\u2022 Convert 111.101101 to Decimal.
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 4
Binary Fractions
\u2013 The Binary Fraction Table
2-1
=
1/2
=
.5
2-2
=
1/4
=
.25
2-3
=
1/8
=
.125
2-4
=
1/16 =
.0625
2-5
=
1/32 =
.03125
2-6
=
1/64 =
.015625
2-7
=
1/128 =
.0078125
2-8
=
1/256 =
.00390625
Example:Convert 2.15625 to Binary. (2 = 102 ..only need to do fraction.)

Starting with the largest fraction that can be used (.125) we take that away.
0.15625 - 0.125 = .03125 (We record that we used the 2-3 fraction)10.001
0.03125 - .03125 = .0 (We record that we used the 2-5 fraction)10.00101

Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 5
Binary Fractions
\u2013 Example Convert 9.3437510 to Binary
(A) 9 in Binary is1001 (8+0+0+1)
(B) We need to convert the fraction part.
.34375 is smaller than2-1 so put a0 down
.34375 is bigger than2-2 so put a1 down
and subtract (.34375 - .25)
.09375 is smaller than2-3 so put a0 down
.09375 is bigger than22-4
-4so put a11 down
and subtract (.09375 - .0625)
.03125 is equal to2-5 so put a1 down and
subtract (.03125 - .03125 = Zero all done)
23 22
21
20
2-12-22-322-4
-42-5
1 0 0
1 ..010
111
2-1
=.5
2-2
=.25
2-3
=.125
2-4
=.0625
2-5
=.03125
2-6
=.015625
2-7
=.0078125
2-8
=.00390625
.34375
-.25
.09375
-.0625
.03125
-.03125
.00000
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 6
Binary Fractions
\u2013Problem:- Convert 5.310 from decimal to binary
5.310
= 4 + 1 + 0.25 + 0.03125+ 0.015625 +. . . . . . . .
= 22 +20 +2-2 +2-5 +2-6....
= 1 0 1 . 0 1 0 0 1 1 0 0 1 1 0 01..
Fractional Numbers which have an exact representation in decimal,
may be repeating fractions in binary.
The Sum of any combination of the binary fractions will result in a
decimal fraction that ends in5.
This implies that all other decimal fractions (including some that end
in 0 or 5 see above) have no exact representation in binary.
2
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 7
Binary Fractions
\u2013 Exercise:
\u2022 Convert 4.75 to Binary.
\u2022 Convert 7.046875 to Binary.
\u2022 Convert 10.4375 to Binary.
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 8
Negative Numbers
Positive Integer numbers are represented simply by their binary
equivalents.
i.e. 3910= 0 0 1 0 0 1 1 1 = 2716
A problem arises when we come to consider the representation of
negative numbers.
One obvious way would be to use bit 7 as a sign bit.
i.e. -39 =1 0 1 0 0 1 1 1 = A716
In this way one byte could represent numbers from
-127 to +127 (Do you know why ?)
Note that this \u201csign and magnitude\u201d representation is the same as
that which we use when representing negative numbers in
decimal. On a computer - It is not done like that
On a com
puter - It is not done like that
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 9
Negative Numbers
\u2013 Before looking at how negative numbers are stored we
\u2013 Rules:
\u2013 Examples:
0 1 1
3
0 1 0 1. 1 1
5.75
+011 0
+2
01 01 11 01 . 01 1
+2.25
1 0 1
5
1 0 0 0. 0 0
8.00

0 + 0 = 0 0 + 1 = 1 1 + 0 = 1

1 + 1 = 0 PLUS aC a r r y of 1
1 + 1 + 1= 1 PLUS aC a r r y of 1
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 10
Negative Numbers
\u2013 Back to School - Subtraction.
\u2022 Subtract 84 from 31.

\u2013 The reason this works is because we are fixing the limits of the resulting numbers (something falls off the end which we ignore.. It actually is stored in the carry flag)

\u2013 This is calledprec i s i on. The result is accurate to a number of
fixed places. Can we use this technique in the computer
where the registers/memory are fixed sizes ?
31
-
84
..99947 ??
84
+9 9 9 947
..000031 Correct !
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 11
Negative Binary Numbers
\u2013 Lets try the same technique on sample binary numbers of
fixed 4-bits in length
0110
6
0100
4
- 0100
4
- 0110
6
0010
2
1110
-2?
0100
4
0110
6
+ 0010
2
+ 1110
-2?
0110
6
0100
4
Thisrepres ent at i on of negative numbers in binary is called2\u2019 s
2\u2019s
Compliment
Compliment
11
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 12
Negative Binary Numbers
\u2013 Positive and Negative 4-bit Binary Numbers table
00000
1000-8
00011
1001-7
00102
1010-6
00113
1011-5
01004
1100-4
01015
1101-3
01106
1110-2
01117
1111-1
3
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 13
2\u2019 s Compliment
\u2013 In 2\u2019s Compliment all positive numbers begin with a \u201c zero\u201d
and all negative numbers begin with a\u201cone\u201d
\u2013One way of getting the negative equivalent of a number is to
subtract it from zero.
0
00000000
0
-
3
- 00100111
39
-3
11011001- 3 9
\u2013 An easier way of converting to/from 2\u2019s Compliment is to
\u201c change all the bits and ADD 1\u201d
\u201c change all the bits and ADD 1\u201d
0 0 1 0 01 1 1
1 10 1 1 0 0 0
+ 1
1 1 0 1 1 0 0 1
All \u201c1\u2019 s\u201d become \u201c0\u2019 s\u201d
All \u201c0\u2019 s\u201d become \u201c1\u2019 s\u201d
1
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 14
2\u2019 s Compliment
\u2013 Example: Convert the 8-bit number 23 to -23.
00010111
Change all 0\u2019s to 1\u2019s
11101000
and 1\u2019s to 0\u2019s
+1
THENA d d1
11101001
(-23)
\u2013 Example: Convert the 8-bit number 19 to -19
00010011
Change all 0\u2019s to 1\u2019s
11101100
and 1\u2019s to 0\u2019s
+1
THENA d d1
11101101
(-23)
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 15
2\u2019 s Compliment
\u2013 Example: Add the 8-bit numbers 19 + (-23)
00010011
8-bit binary 19
+11101001
8-bit binary(-23)
11111100
The answer is a minus number (Most Significant Bit is 1) so
convert it to a positive number
1 1 1 1 1 10 0
00000011
Invert all the digits
+1
00000100
the sign is minus)
19 + (-23) = -4. The computer hasno subtraction circuitry so
this is really how it works. When it needs to performA -B it
converts +B to -B and thenADDS
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 16
Exercises
\u2013 Convert the following numbers to their 8-bit binary
equivalents.
\u2022 17
11
22
19
13
15
\u2022 -17 -11
-22
-19
-13
-15
\u2013 Show how a computer would perform the following 8 bit
binary calculations
\u2022 17 - 11
(Remember it\u2019 s[ 17 + (-11) ] )
\u2022 11 - 17
\u2022 22 - 19
\u2022 13 - 15
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 17
Multi-Byte Numbers
Largest positive number in 8-bit location (127)
Largest negative number in 8-bit location (-128)
Q. Using 2\u2019s compliment the range of numbers in 8-bits is -128 to +127 but
using sign and magnitude it\u2019 s -127 to +127. Why ?
Q. How can we store larger numbers ?
A. Use more bytes.
151413121110 9 8
7 6 5 4 3 2 1 07 6 5 4 3 2 1 0
01111111
10 000000
01111001
10101000
Most Significant Byte
Least Significant Byte
Using two bytes, numbers can be stored in the range -32,768 to +32,767
Spring 2001
CA103 Computer Architecture
Ra y Walshe
Page 18
Floating Point Numbers
\u2013 Larger numbers than this can be stored using floating pint
representation.
\u2013 Any Real Number can be divided into two parts
TheMant is s a and theE x ponent
27.325 = .27325 x 10
.000762 =.762
x 10
1,000,000 = .1
x 10
2-3
7