Data Representation
Data Representation
THE COMPUTER
Objectives:
At the end of the module, the students shall be able to:
1. Perform arithmetic operations for the different number systems
2. Represent signed numbers
3. Represent fractional numbers
Fractional Part
1. Multiply the fractional part by the value of the new base (i.e. in 45.73 10 =0.73 x 2;
where 2 is the new base or target base)
2. Record the integer part if it exits, else record 0.
3. Repeat step 1 with the result of the previous multiplication and then step 2, until the
fractional part becomes 0. In case of infinite calculations, generally 6 digits are taken.
Example:
Fractional Part
0.75 x 2 = 1.5, Integer part = 1
0.5 x 2 = 1.0, Integer part = 1
Binary Number 1 1 0 1 0
Weight of each bit 24 23 22 21 20
Weighted Value 24 * 1 23 * 1 22 * 0 21 * 1 20 * 0
Solved Multiplication 16 8 0 2 0
Sum of weight of all bits = 16 + 8 +0 + 2 + 0 = 26
Thus, the decimal equivalent of (11010)2 is (26)10
Example:
a. Convert 10112 to Decimal number system
1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 8 + 0 + 2 + 1 = 1110
b. Convert 3568 to Decimal number system
3 x 82 + 5 x 81 + 6 x 80 = 192 + 40 + 6 = 23810
Example:
4 + 2×3 = 4 + (2×3) = 4 + 6 = 10
Which answer is the right one? Arithmetic operations follow the following order of
precedence:
1. Parentheses ()
2. Exponents
3. Multiplication and Division (from left to right)
4. Addition and Subtraction (from left to right)
For example: in decimal addition, if you add 8 + 2 you get ten, which you write as 10;
in the sum this gives a digit 0 and a carry of 1. Something similar happens in binary
addition when you add 1 and 1; the result is two (as always), but since two is written
as 10 in binary, we get, after summing 1 + 1 in binary, a digit 0 and a carry of 1.
Therefore in binary:
0+0=0 1–1=0
0+1=1 1–0=1
1+0=1 0 – 1 = 1 (borrow 1)
1 + 1 = 10 (which is 0 carry 1) 0–0=0
Examples:
Add 23 and 52 Subtract 23 from 52
1 0111 11 0100
+ 11 0100 - 1 0111
100 1011 1 1101
c. Binary Multiplication
In the multiplication, the digits of the multiplier are stepped through one at a time,
from right to left. Each digit of the multiplicand is then multiplied, in turn, by the
current multiplier digit; taken together, these single-digit multiplications form a
partial product. The answer to each single-digit multiplication comes from the
multiplication table. Some of these answers are double-digit numbers, in which case
the least significant digit is recorded and the most significant digit is carried over to
be added to the result of the next single-digit multiplication.
Example: 1011.01 x 110.1
1 0 1 1.0 1
x 1 1 0.1
101101
000000
101101
1 0 1 1 0 1 __
1 0 0 1 0 0 1.0 0 1
d. Binary Division
Binary division is almost as easy to calculate as multiplying binary numbers, and
involves our knowledge of binary multiplication. Be sure to review binary
multiplication first.
a. 0 b. 01 c. 010
11/1101 11/1101 11/1101
0 0 0
1 11 11
Note:
1/11 = 0 ;since 1<11 11 11
0 00
Note:
11/11 = 1 00
0
Note:
00/11 = 0
d. 0100
11/1101
0
11
11
00
00
01
Note:
00/11 = 0
e. Octal Division
Divide 34438 and 78
Step 2: Divide
4 0 5
7/3 4 4 3
3 4 ; 4 8 x 78
0 4 ; 04 is less than 8, thus, quotient is 0
0 ; 0 8 x 78
4 3
4 3 ; 58 x 78
0
Representation of floating point number is not unique. For example, the number
55.66 can be represented as 5.566×10^1, 0.5566×10^2, 0.05566×10^3, and so on. The
fractional part can be normalized. In the normalized form, there is only a single non-
zero digit before the radix point. For example, decimal number 123.4567 can be
normalized as 1.234567×10^2; binary number 1010.1011B can be normalized as
1.0101011B×2^3.
It is important to note that floating-point numbers suffer from loss of precision when
represented with a fixed number of bits (e.g., 32-bit or 64-bit). This is because there
are infinite number of real numbers (even within a small range of says 0.0 to 0.1). On
the other hand, a n-bit binary pattern can represent a finite 2^n distinct numbers.
Hence, not all the real numbers can be represented. The nearest approximation will
be used instead, resulted in loss of accuracy.
It is also important to note that floating number arithmetic is very much less efficient
than integer arithmetic. It could be speed up with a so-called dedicated floating-point
co-processor. Hence, use integers if your application does not require floating-point
numbers.
The most significant bit is the sign bit (S), with 0 for positive numbers and 1 for
negative numbers.
The following 8 bits represent exponent (E).
The remaining 23 bits represents fraction (F).
Normalized Form
Suppose that the 32-bit pattern is 1 1000 0001 011 0000 0000 0000 0000 0000, with:
In the normalized form, the actual fraction is normalized with an implicit leading 1 in
the form of 1.F. In this example, the actual fraction is 1.011 0000 0000 0000 0000 0000
Step 5: Sign
In this example with S=1, this is a negative number, thus, -1.37510.
Example 1: Given -5.510, show its single precision floating point data representation
Step 1: Convert decimal in its binary representation (use remainder method and etc.)
5.510 = 101.1
Example 2: Given 52.72510, show its single precision floating point data representation