0% found this document useful (0 votes)
3 views

7-8 Data Representation and Computer Arithmetic

The document provides an overview of data representation in computer organization, focusing on decimal, binary, and hexadecimal systems. It explains how numbers are represented using positional notation, including conversions between decimal and binary formats, and discusses the significance of the most and least significant digits. Additionally, it covers the concept of two's complement for representing signed binary numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

7-8 Data Representation and Computer Arithmetic

The document provides an overview of data representation in computer organization, focusing on decimal, binary, and hexadecimal systems. It explains how numbers are represented using positional notation, including conversions between decimal and binary formats, and discusses the significance of the most and least significant digits. Additionally, it covers the concept of two's complement for representing signed binary numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

+

Computer Organization
INT203

Data representation and computer arithmetic


+
The Decimal System
 System based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to
represent numbers

 For example the number 83 means eight tens plus three:

83 = (8 * 10) + 3

 The number 4728 means four thousands, seven hundreds, two


tens, plus eight:

4728 = (4 * 1000) + (7 * 100) + (2 * 10) + 8


 The decimal system is said to have a base, or radix, of 10. This
means that each digit in the number is multiplied by 10 raised to
a power corresponding to that digit’s position:

83 = (8 * 101) + (3 * 100)

4728 = (4 * 103) + (7 * 102) + (2 * 101) + (8 * 100)


+
Decimal Fractions
 The same principle holds for decimal fractions, but negative
powers of 10 are used. Thus, the decimal fraction 0.256 stands for
2 tenths plus 5 hundredths plus 6 thousandths:

0.256 = (2 * 10-1) + (5 * 10-2) + (6 * 10-3)

 A number with both an integer and fractional part has digits


raised to both positive and negative powers of 10:

442.256 = (4 * 102) + (4 + 101) + (2 * 100) + (2 * 10-1) + (5 * 10-2)

+ (6 * 10-3)

 Most significant digit


 The leftmost digit (carries the highest value)

 Least significant digit


 The rightmost digit
Table 9.1
Positional Interpretation of a Decimal Number

4 7 2 2 5 6
100s 10s 1s tenths hundredths thousandths
102 101 100 10–1 10–2 10–3
position 2 position 1 position 0 position –1 position –2 position –3
+
Positional Number Systems

 Each number is represented by a string of digits in which


each digit position i has an associated weight ri, where r is
the radix, or base, of the number system.

 The general form of a number in such a system with radix r is

( . . . a3a2a1a0.a-1a-2a-3 . . . )r

The dot between a0 and a-1 is called the radix point.


Table 9.2
Positional Interpretation
of a Number in Base 7

Position 4 3 2 1 0 –1
Value in
exponential 74 73 72 71 70 7–1
form
Decimal
2401 343 49 7 1 1/7
value
+ The Binary System
 Only two digits, 1 and 0

 Represented to the base 2

 The digits 1 and 0 in binary notation have the same meaning as in decimal
notation:

02 = 010

12 = 110

 To represent larger numbers each digit in a binary number has a value


depending on its position:

102 = (1 * 21) + (0 * 20) = 210

112 = (1 * 21) + (1 * 20) = 310

1002 = (1 * 22) + (0 * 21) + (0 * 20) = 410

and so on. Again, fractional values are represented with negative powers of the
radix:

1001.101 = 23 + 20 + 2-1 + 2-3 = 9.62510


+ Binary notation to
decimal notation:
 Multiply each binary digit
by the appropriate power
of 2 and add the results

Decimal notation to
binary notation:
 Integer and fractional parts
are handled separately

Converting Between
Binary and Decimal
For the integer part, recall that in binary notation, an integer represented by
bm-1bm-2 . . . b2b1b0 bi = 0 or 1

has the value Integers


(bm-1 * 2m-1) + (bm-2 * 2 m-2) + . . . + (b1 * 21) + b0
Suppose it is required to convert a decimal integer N into binary form. If we
divide N by 2, in the decimal system, and obtain a quotient N1 and a
remainder R0, we may write

N = 2 * N 1 + R0 R0 = 0 or 1

Next, we divide the quotient N1 by 2. Assume that the new quotient is N2


and the new remainder R1. Then

N 1 = 2 * N 2 + R1 R1 = 0 or 1

so that

N = 2(2N2 + R1) + R0 = (N2 * 22) + (R1 * 21) + R0

+ If next

N2 = 2N3 + R2

we have

N = (N3 * 23) + (R2 * 22) + (R1 * 21) + R0


Continued . . .
Integers
Because N >N1 > N2 . . . , continuing this sequence will
eventually produce a quotient Nm-1 = 1 (except for the
decimal integers 0 and 1, whose binary equivalents
are 0 and 1, respectively) and a remainder Rm-2, which
is 0 or 1. Then

N = (1 * 2m-1) + (Rm-2 * 2m-2) + . . . + (R2 * 22) + (R1 * 21) + R0

which is the binary form of N. Hence, we convert from


base 10 to base 2 by repeated divisions by 2. The
remainders and the final quotient, 1, give us, in order
of increasing significance, the binary digits of N.
+
10112 = 1110
2
(a) 1110

5 = 2 1
Quotient Remainder
11 = 5
21 Quotient Remainder
2 21 = 10 1
2
5 = 2 21 = 1 0
2 10 =
2 =
2 2
5 0
1 0
2 5 = 2 1
1 = 0
11 = 0
2
1
2
2 1011 = 1110
2 =
2
1 0
2

(a) 1110 1 = 0
10101
1 2
= 2110
2
101012 = 2110
(b) 2110 (b) 2110
Quotient Remainder
21 = 10 1
2 Figure 9.1 Examples of Converting from Decimal
Notation to Binary Notation for Integers
10 = Figure
5
9.1
0
Examples of Converting from Decimal
2
Notation to Binary Notation for Integers
5 = 2 1
2

2 = 1 0
2
For the fractional part, recall that in binary notation,
a number with a value between 0 and 1 is
represented by Fractions
0.b-1b-2b-3 . . . bi = 0 or 1
and has the value
(b-1 * 2-1) + (b-2 * 2-2) + (b-3 * 2-3) . . .
This can be rewritten as
2-1 * (b-1 + 2-1 * (b-2 + 2-1 * (b-3 + . . . ) . . . ))
Suppose we want to convert the number
F (0 < F < 1) from decimal to binary notation. We
know that F can be expressed in the form
+
F = 2-1 * (b-1 + 2-1 * (b-2 + 2-1 * (b-3 + . . . ) . . . ))
If we multiply F by 2, we obtain,
2 * F = b-1 + 2-1 * (b-2 + 2-1 * (b-3 + . . . ) . . . )
Continued . . .
From this equation, we see that the integer part of
(2 * F), which must be either 0 or 1 because Fractions
0 < F < 1, is simply b-1. So we can say (2 * F) = b-1 +
F1, where 0 < F1 < 1 and where

F1 = 2-1 * (b-2 + 2-1 * (b-3 + 2-1 * (b-4 + . . . ) . . . ))

To find b−2, we repeat the process.


At each step, the fractional part of the number
from the previous step is multiplied by 2. The digit
to the left of the decimal point in the
product will be 0 or 1 and contributes to the
binary representation, starting with the
+most significant digit. The fractional part of the
product is used as the multiplicand
in the next step.
0.62 2 = 1.24 1
Product Integer Part 0.110011 2
0.81 2 = 1.62 1
0.24 2 = 0.48 Figure
0 9.2

0.62 2 = 1.24 1
0.48 2 = 0.96 0
Examples of
0.24 2 = 0.48 0
Converting
0.96 2 = 1.92 1
0.48 2 = 0.96 0
from
0.92 2 = 1.84
Decimal 1Notation
0.96 2 = 1.92 1 To
(a) Binary2 Notation
0.81 10 = 0.110011 (approximately)
0.92 2 = 1.84 1
For Fractions
(a) 0.81 10 = 0.110011 2 (approximately)

Product Integer Part 0.012


0.25 2 = 0.5 0
Product Integer Part 0.012
0.25 2 = 0.5 0
0.5 2 = 1.0 1
0.5 2 = 1.0 1
(b) 0.25 10 = 0.012 (exactly)
(b) 0.25 10 = 0.012 (exactly)
+
Hexadecimal Notation
 Binary digits are grouped into sets of four bits, called a nibble

 Each possible combination of four binary digits is given a


symbol, as follows:

0000 = 0 0100 = 4 1000 = 8 1100 = C


0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F

 Because 16 symbols are used, the notation is called hexadecimal


and the 16 symbols are the hexadecimal digits

 Thus

2C16 = (216 * 161) + (C16 * 160)

= (210 * 161) + (1210 * 160) = 44


Decimal Binary (base 2) Hexadecimal
(base 10) (base 16)

+ 0
1
0000
0001
0
1
2 0010 2
3 0011 3
4 0100 4
5 0101 5

Table 9.3 6 0110 6


7 0111 7
8 1000 8

Decimal, Binary,
9 1001 9
10 1010 A

and 11
12
1011
1100
B
C

Hexadecimal 13
14
1101
1110
D
E
15 1111 F
16 0001 0000 10
17 0001 0001 11
18 0001 0010 12
31 0001 1111 1F
100 0110 0100 64
255 1111 1111 FF
256 0001 0000 0000 100
Hexadecimal Notation

Not only used for


representing integers but
also as a concise notation
for representing any Reasons for using
sequence of binary digits hexadecimal notation
are:

In most computers,
binary data occupy some It is extremely easy to
It is more compact than
multiple of 4 bits, and convert between binary
binary notation
hence some multiple of a and hexadecimal notation
single hexadecimal digit
Two’s compliment
• In the Binary System, there are only two symbols or possible digit
values, i.e., 0 (off) and 1 (on).

• Generally, there are two types of complement of Binary number: 1’s


complement and 2’s complement. To get 1’s complement of a binary
number, simply invert the given number. For example, 1’s complement
of binary number 110010 is 001101.

• To get 2’s complement of binary number, take 1’s complement of given


number plus 1 to the least significant bit (LSB). For example 2’s
complement of binary number 10010 is (01101) + 1 = 01110.
Binary number 1’s complement 2’s complement

000 111 000

001 110 111

010 101 110

011 100 101

100 011 100

101 010 011

110 001 010

111 000
001
Uses of 2’s Complement Binary Numbers

• There are various uses of 2’s complement of


Binary numbers, mainly in signed Binary
number representation and various arithmetic
operations for Binary numbers, e.g.,
additions, subtractions, etc. Since 2’s
complement representation is unambiguous,
it is very useful in Computer number
representation.
2’s Complementation in Signed Binary
number Representation
Positive numbers are simply represented as simple Binary
representation. But if the number is negative then it is
represented using 2’s complement. First represent the number
with positive sign and then take 2’s complement of that
number.
Example − Suppose we are using 5 bit registers. The
representation of -5 and +5 will be as follows:
Subtractions by 2’s Complement

• There are various uses of 2’s complement of


Binary numbers, mainly in signed Binary
number representation and various arithmetic
operations for Binary numbers, e.g.,
additions, subtractions, etc. Since 2’s
complement representation is unambiguous,
so it very useful in Computer number
representation.
Example (Case-1: When Carry bit 1) −Evaluate 10101 - 00101
Take 2’s complement of subtrahend 00101, which will be 11011,
then add both of these. So, 10101 + 11011 =1 10000. Since, there is
carry bit 1, so dropped this carry bit 1, and take this result will be
10000 will be positive number.

Example (Case-2: When no Carry bit) −Evaluate 11001 - 11100


Take 2’s complement of subtrahend 11110, which will be 00100.
Then add both of these, So, 11001 + 00100 =11101. Since there is
no carry bit 1, so take 2’s complement of above result, which will be
00011, and this is negative number, i.e, 00011, which is the answer.

You might also like