CHAPTER 2 Data Representations
CHAPTER 2 Data Representations
DATA REPRESENTATIONS
Several formats are used to store data.
Because a computer uses binary numbers all these formats are
patterns of 1’s and 0’s.
These binary digits are called BITS.
In Computer circuits, 0’s and 1’s are voltage levels where a 0 is
low voltage / OFF and a 1 is high Voltage /ON
NUMBER FORMATS
Integer Formats
Human beings are trained to understand decimal system.
e.g. 5437 = 5000 + 400 + 30 + 7 = (5 * 103) + (4 * 102) + (3 * 101) + (7 * 100)
In Binary
11011 = (1 * 24) + (1 * 23) + (0 * 22) + (1 * 21)+ (1 * 20) = 16 + 8 + 0 + 2 + 1 = 2710
Hexadecimal
It has 15 digits 0 – 15
Decimal Hexadecimal Binary Octal
0 0 0000 0
1 1 0001 1
2 2 0010 2
3 3 0011 3
4 4 0100 4
5 5 0101 5
6 6 0110 6
7 7 0111 7
8 8 1000 10
9 9 1001 11
10 A 1010 12
11 B 1011 13
12 C 1100 14
13 D 1101 15
14 E 1110 16
15 F 1111 17
16 10 10000 20
411 / 16 = 25 rem 11 B
25/16 = 1 rem 9 9 => 41110 = 19B16
Octal System
Each octal digit can be represented by a unique combination of three
bits.
e.g. to convert 1100110112 to base 8 first covert to decimal then perform
successive divisions of 8 on the decimal number.
1100110112 = 41110
411/8 = 51 rem 3
51/8 = 6 rem 3 => 1100110112 = 41110 = 6338
13 = 1101 1 0 1 1
.6875 * 2 = 1.375
.375 * 2 = 0.75
.75 * 2 = 1.5
.5 * 2 = 1.0
=> 13.6875 = 1101.1011
Similarly 150.312510 = 10010110.01012
If a binary number contains digits to the right of the decimal point
we convert them by starting at the binary point and move to the
right.
e.g. 11.10100110112 = 011 101 001 101 100 = 3.51548
= 0011 1010 0110 1100 = 3.A6C16
Similarly
5.1458 = 101 001 100 101 = 0101 0011 0010 1000 = 5.32816
Just like in Base 10 the decimal point can be moved by multiplying
by the appropriate power of the base.
e.g. 101.11 = 1011 * 2-2 = 0.1011 * 23
Binary Arithmetic
110101 101101 10110 11111101 / 1011
+ 10010 -100110 * 1011
1000111 111
BA41 BA41
+ 14AF -14AF
CEF0 A592
We usually estimate high powers when the groups are large where n
may be 24, 32, 64 etc.
210 = 1024 = 103
e.g. 236 = 26.230 = 26(210)3 = 26(103)3 = 64 * 109
If the result of any operation does not fit into the number of bits reserved
for it an overflow is said to occur.
All the 4 arithmetic operations can cause an overflow.
360 + 720 – 300 = 360 + (720 – 300) and (360 + 720) – 300
SIGNED INTEGERS
Normally a negative number is written by writing its magnitude and then
placing a negative sign to the left of the magnitude of the number.
A computer element can take only a 0 or 1; so a minus sign must
be represented by a 0 or a 1.
If a number is to be stored in n bits, the magnitude is placed in the
n – 1 right most bits and the MSB represents the sign.
A negative number is represented by a 1 and a positive number by
a 0.
Such a format is called the Sign Magnitude Format.
In this format there is a difference between – 0 and + 0 but they both
have the same magnitude.
The range of integers that can be expressed in a group of 8 bits is
from – (27 – 1) = -127 to (27 – 1) = +127
In general a d bit binary sign magnitude representation in which the
first bit represents the sign has a range of
– (2d-1 – 1) to + (2d-1 – 1).
To add two sign magnitude numbers, we follow the usual addition rules.
If the sign differs we subtract the smaller number from the larger
number and give the result the sign of the larger number.
If the signs are the same we add them and we give the result the
same sign.
+5 + -7 = 10000111 -5 + -7 = 10000101
- 00000101 - 10000111
10000010 (-2) 10001100 (-12)
COMPLEMENTS
They are used to simplify subtraction & logical operations.
Consider numbers –1000 to 999 and let X be any number in that range.
The 4 digit 10’s complement of X is defined as 104 – X
If X = 0572, the 4 digit 10’s complement of X is 10000 – 0572 = 9428
(i) A 9 in the most significant Digit indicates that the sum is negative.
If the magnitude is wanted the 10’s complement of the sum is taken.
i.e. 104 – 9832 = 0162
(ii) N.B. The most significant digit is reserved to represent the sign
leaving 3 digits for the magnitude.
2’s Complement
The d digit 2’s complement of a d bit binary integer N is equal to
2d – N where the subtraction is done in binary.
=> The eight bit 2’s complement of an 8 bit binary number 000000101
is 100000000 – 00000101 = 11111011
N.B. Note the difference between the sign magnitude representation and
the 2’s complement representation.
Rules to convert to decimal:
(i) If a number is positive (beginning with a 0), convert it to
base 10 directly as usual.
(ii) If it is negative (begins with 1) get its 2’s complement and
convert it to base 10.
e.g. to convert a 2’s complement number 11111001 to decimal:
It is a 2’s complement number; it is negative because it
begins with a 1
Get its complement ; i.e. 11111001 Invert 00000110 + 1 =
00000111 = - 7
The fraction part is sometimes called the significand and the exponent
the characteristic.
A floating point format is designated by:
(i) The base
(ii) The number of bits reserved for the exponent
(iii) The number of bits reserved for the fraction
(iv) The method for storing the sign and magnitude of
the exponent
(v) The method for storing the sign and magnitude of
the fraction.
(vi) The order in which the two signs and the two
magnitudes are to occur.
The combination of the above factors for a given computer depends
upon the designer.
Steps in Arithmetic
1. Pre-normalisation if the operands are not normalized.
2. Alignment
3. Post normalization of the result.
Examples
(1) 826013AC Alignment 826013AC
+8040AB04 82102AC1
82703E6D
Examples
(1) 40700000 (2) 40C00000 No Alignment
+C0580000 + C0800000
40180000 3EC00000 40C00000 40000000
Hardware designed for BCD is more complex than that for binary
formats. E.g. 16 bits are used to write 8159 in BCD while only 13
bits (1111111011111) would be required in binary.
ALPHANUMERIC CODES
It is the assignment of bit combinations to the letters of the alphabet,
decimal digits 0 – 9, punctuation marks and several special characters.
The two most prominent Alphanumeric Codes are:
1. EBCDIC (Extended Binary Coded Decimal Interchange Code); this
is mostly used by IBM.
2. ASCII: (American Standard Code for Information Interchange);
used by other manufacturers.
ASCII represents each character with a 7 bit string
The total number of characters that can be represented is 27 = 128
e.g. J O H N = 4A 6F 68 6E = 1001010 110111 1101000 1101110
Since most computers manipulate an 8 bit quantity, the extra bit when 7
bit ASCII is used depends on the designer. It can be set to a particular
value or ignored.
EXPRESSION EVALUATION
When writing an algebraic expression we use parenthesis to
indicate the order in which the elementary operations are to be
performed.
If the ordering is specified by using parenthesis the expression is
said to be in an infix notation because the operators are placed
between their operands.
The postfix or reverse Polish Notation places operators after the
operands.
e.g.: A/(B + C) = ABC+/
(A + B) * [C * (D + E) + F] = AB+CDE+*F+*