CompOrgW1LRadix bina..

Download Report

Transcript CompOrgW1LRadix bina..

Computer Organization 1
Representation of Data
Numbers and Counting




We have seen that we can use any handy
base to count in – decimal, duodecimal, base
8, binary, vigesimal
Early attempts to use decimal in computers
were too costly – too many unreliable valves
to represent a decimal digit
Von Neuman advocated binary – in use since
Binary not suitable for human perception –
we use hexadecimal to express binary
patterns
Problems in Representing data in Binary






Radix conversion
Fixed length of numbers in computers
negative number representation
Representation of fractions
Range and Precision
Symbols (eg alphabets) : ASCII and
Unicode standards
Radix Conversion




Any number can be written to any base
eg Base (Modulo) 7
To Convert 143.4 (base 7) to Decimal
(Polynomial Method):
(143.4)7 = 1 x 7^2 + 4 x 7^1 +
3 x 7^0 + 4 x 7 -1
= (80.555)10
Radix Conversion






To Convert from decimal to Base 7, Divide
repeatedly by 7, Save the Remainders. (the
Remainder method) eg (204)10
Divide 7 into 204 : 29 rem 1
Divide 7 into 29 : 4 rem 1
Divide 7 into 4
: 0 rem 4 MSD (Most
Significant Digit)
20410 = 4117
To convert fractions, from base 10 to base 7, say,
we can use the Multiplication method
Radix Conversion - Multiplication Method for
fractions
(0.235)10
Multiply by 7 repeatedly, save the Most Significant
Digit
 .235 x 7 = 1.645
Save the 1 before point - MSD
 .645 x 7 = 4.515
Save the 4
 .515 x 7 = 3.605
Save the 3
 .605 x 7 = 4.235
Save the 4
 .235 x 7 = 1.645
etc
 So, (0.235)10 is equivalent to (0.143414)7

Radix Conversion








To convert a mixed (real) number from one radix
to another, we can combine the Remainder
method and the Multiplication method:
Convert 14.275 base 10 to binary.
14 by Remainder method:
14 divide by 2 = 7 remainder 0
7 / 2 = 3 rem 1
3 /2 = 1 rem 1
1 /2 = 0 rem 1 MSD
Thus, decimal 14 is 1110 in binary.
Convert 14.275 base 10 to binary.










decimal 14 is 1110 in binary.
.275 x 2 = 0.550 - this 0. is the MSD
.550 x 2 = 1.10
.10 x 2 = 0.2
.2 x 2 =
0.4
.4 x 2 =
0.8
.8 x 2 =
1.6
.6 x 2 =
1.2
0.275 gives .0100011 in binary
Thus, 14.275 is 1110.0100011 in binary
Problems representing numbers
1. Fixed Length `Words' in Computer
– problems of Overflow, Range and
Precision.
 2. Negative Numbers
 3. Fractions

Precision and Overflow




Computer numbers are limited by the number
of bits allocated to them.
For example, a computer designer may
allocate 32 bits for an integer.
Suppose we multiply 2 of these 32 bit
integers, to find that the result is too big for
result 32 bits.
This is called Overflow, and steps must be
taken to avoid it.
Range and Precision



Suppose we are allowed to have numbers of only
3 digits.
If we decide to have only integers, then the
range of numbers goes from 000 to 999. The
precision is 1.0. That is, the nearest we can get
to an accurate ‘result’ is 1.0.
If we decide to have only numbers with the
decimal point placed two digits from the right, the
range becomes 0.00 to 9.99. Thus the range is
much shorter, but the precision is 0.01.
Range and Precision


We can see how range and precision in fixed length
numbers trade off. The greater the range, the less
precise the number is, and vice versa.
In any case, there are only 103 different decimal
numbers ranging from 000 to 999, or from .000 to
.999, and so it is possible to represent only 1000
different numbers, regardless of how we apportion
the range and precision.
How many bits do we need in a group to
represent 'meaningful' data?



1 bit - 0, 1 (2 Representations)
2 bits : 00, 01, 10, 11, that is 4 representations,
distinct patterns
3 bits : 000 001 010 011 100 101 110 111

that is, 8 representations

4 bits gives us 16 distinct patterns
7 bits gives us 128 unique patterns

8 bits gives 256 unique patterns

Other symbol Representation



To represent 26 (upper-case) letters, 10 digits,
20 other characters such as ?, !, £, :, ;, etc.
about 56 distinct patterns are required.
That is, a group of at least 6 bits is needed for a
basic extended`alphabet' of 64 different symbols.
Used in so-called ‘Character’ machines of 60s (2nd
Generation) era
Other Symbol Representation



We need 7 bits (128 representations) for the Latin
alphabet, decimal digits and special characters
ASCII codes (American Standard Code for
Information Interchange) are 7-bit codes (usually
written as 8 bits) which are accepted as an
international standard for the connection of computer
devices from different sources and manufacturers.
Each ASCII code represents a letter, digit, or special
character.
Another accepted standard 8-bit code is EBCDIC (Extended Binary Coded Decimal Interchange Code).
Symbol Representation


a new character standard has been developed to
support most of the world’s character sets –
Unicode.
Unicode uses 16 bits to give up to 65,536 distinct
representations. (Version 2.0 of Unicode contains
38,885 characters, and this covers the principal
written languages of the Americas, Europe, Middle
East, India and Asia.)
Hexadecimal and Binary arithmetic







The contents of a BYTE (a grouping of 8 bits) may
be written down as 2 Hex digits.
eg
Byte :
0101 1010
Hex :
5
A
All computer memory addresses are expressed in
hexadecimal.
For example, a 32-bit address
0000 1010 0011 1110 0101 0001 0010 1101 is
0
A
3
E
5
1
2
D
Binary Arithmetic

Binary Arithmetic is no different in principle
from decimal arithmetic - just as the only
allowable symbols in decimal are 0-9, in binary
the range of symbols is restricted to 1 and 0.
Binary Arithmetic




Subtract:
-
011
001
----010
100
- 110
----11110
Binary Arithmetic
Binary Arithmetic
Binary Arithmetic


From the above, there are several examples
of `Overflow' required from 3-bit patterns
to 4 or more bits, to give the exact result.
This can cause problems in computer
systems, where there are generally fixedlength groups of bits to hold data, and steps
must be taken by computer designers to deal
with overflow problems.
Binary Arithmetic


1111 1111 1111 1111
This is equivalent to decimal 65,535. In fact,
it is usual to use a 2-byte pattern to hold
both positive and negative integers, as
follows:
Binary Arithmetic - Integers





Since 8 bits can only have 256 distinct
patterns, the largest positive decimal integer
that can be held in 8 bits is 255:
1111 1111 - hex FF
This means that bytes must be further
grouped together to provide for decimal
integers of a reasonable size.
A 2-byte group can hold a pure binary
integer of maximum size
1111 1111 1111 1111 ie 65,535
Summary




Convert from decimal to base x by the remainder method:
divide the decimal number by x, keep the remainders.
Convert a number from any base x to decimal by using the
polynomial method: multiply digit y in position z by x to the
power z-1. Count positions from left.
Numbers in computers have fixed lengths; this affects the
range and precision of the number.
We need at least 6 bits to represent human-compatible
data; most common encoding for human symbols is ASCII,
which takes 7 digits – usually extended to the 8-bit byte, the
basic unit of computer storage.