0% found this document useful (0 votes)
13 views9 pages

COA Chapter 2

Uploaded by

abduwasi ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

COA Chapter 2

Uploaded by

abduwasi ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Chapter 2

Data Representation

Data – refers to factual information used for analysis.


Information – is a collection of facts or data that is communicated.

Binary information in digital computers is stored in memory or processor registers. Registers contain either
data or control information.

Control information is a bit or a group of bits used to specify the sequence of command signals needed for
manipulation of the data in other registers.

Data are members and other binary-coded information that are operated on to achieve required
computational results.

Data types found in the registers of digital computers:


1. Numbers used in arithmetic computations,
2. Letters of the alphabet used in data processing, and
3. Other discrete symbols used for specific purposes.

All types of data, except binary numbers, are represented in computer registers in binary-coded form. This is
because registers are made up of flip-flops and flip-flops are two-state devices that can store only 1’s and
0’s.

Binary-Coded-Octal(BCO) and Binary-Coded-Hexadecimal(BCH) Conversion:


Since 23=8 and 24=16, each octal digit corresponds to three binary digits and each hexadecimal digit
corresponds to four binary digits.

Ex.: BCO :

Ex.: BCH:

BCO:
Starting from the lower-order bit, we partition the register into groups of three bits each . Each group
of three bits is assigned its octal equivalent.

BCH:
Starting from the lower-order bit, we partition the register into groups of four bits and corresponding
hexadecimal equivalent of each group is assigned.

Note: comparing the binary-coded octal and hexadecimal numbers with their binary number equivalent we
find that the bit combination in all three representations is exactly the same.

Ex: consider decimal 99, when converted to binary, if becomes 1100011.


1 4 3
The BCO equivalent is 001 100 011
The BCH equivalent is 0110 0011 (neglect the leading zeros)
6 3
Advantage of BCO, BCH
The registers in digital computers contain many bits. Specifying the content of registers by their
binary values will require a long string of binary digits.
It is more convenient to specify content of registers by their octal or hexadecimal equivalent. The
numbers of digits used to represent is reduced by one third in the octal designation and by one-fourth in the
hexadecimal designation.

Ex: 1111 1111 1111 – 12 digit binary


7777 – 4 digit octal
FFF – 3 digit Hexadecimal

Decimal representation:
Decimal numbers enter the computer usually as binary-coded alphanumeric characters. These codes,
(ASCII) may contain from six to eight bits for each decimal digit.
When decimal numbers are used for internal arithmetic computations they are converted to a binary
code with four bits per digit.

Binary code:
A binary code is a group of n bits that assume up to 2n distinct combinations of 1’s and 0’s with each
combination representing one element of the set that is being coded.

BCD: (Binary-coded-Decimal)
It is very important to understand the difference between the conversion of decimal numbers into binary and
the binary coding of decimal numbers.

Ex: Decimal number 99 binary equivalent is: 1100011


BCD form is: 1001 1001
9 9
A 4-bit decimal code requires four-flip flops for each decimal digit.
Ex: The representation of 4385 in BCD requires. 16 flip-flops, four flip-flops for each digit.
4 3 8 5
0100 0011 1000 0101

Disadvantages: By representing numbers in decimal using BCD, we are wasting a considerable amount of
storage space since the number of bits needed to store a decimal number in a binary coded decimal (BCD) is
greater than the number of bits needed for its equivalent binary representation.

Also, the circuits required to perform decimal arithmetic are more complex.

Advantage: Input and output data are generated by people who use the decimal system, require small
amount of arithmetic computations compared to the amount required for input and output of decimal data.

Ex: Business data processing application.

Complements: Complements are used in digital computers for simplifying the subtraction operation and for
logical manipulation. There are two types of complements for each base r system: the r’s complement and
(r-1)’s complement.

For binary numbers: 2’s complement and 1’s complement.


For decimal numbers: 10’s complement and 9’s complement

(r-1)’s complement: Given a number N in base r having n digits, the (r-1)’s complement of N is defined as
(rn-1) – N.
9’s complement: For decimal numbers r=10 and (r-1)=9, so the 9’s complement of N is (10n-1)-N.
(106=1000000) (106-1 = 999999)

Ex: Find 9’s complement of 546700?


Here n=6, 106-1 = 999999
(-) 546700 (N)
9’s complement of 546700 is 453599

Thus the 9’s complement of a decimal number is obtained by subtracting each digit from 9.

1’s complement: For binary numbers, r=2 and r-1=1, so the 1’s complement of N is (2n-1) – N.

Ex: Find 1’s complement of 1011001?


Here n=7 (27-1) = 1111111
(-N) 1011001
1’s complement of 1011001 is 0100110

Thus the 1’s complement of a binary number is obtained by subtracting each digit from 1.

Note: The 1’s complement of a binary number is formed by changing 1’s into 0’s and 0’s into 1’s

The (r-1)’s complement of octal or hexadecimal numbers are obtained by subtracting each digit from 7 or F
respectively.

r’s complement:
The r’s complement of an n-digit number N is base r is defined as rn-N for N≠0 and 0 for N=0.

Comparing with the (r-1)’s complement we note that the r’s complement is obtained by adding 1 to the (r-
1)’s complement since rn-N = [(rn-1)-N]+1.

Ex: 10’s complement of the decimal 2389 is


9999
2389
7610
+1
7611

2’s complement of binary 101100 is


111111
101100
010011
+1
010100

Note:
The complement of the complement restores the number to its original value. The r’s complement of N is
rn-N. The complement of the complement is rn-(rn-N) = N giving back the original number.

Subtraction of Unsigned numbers:


In manual subtraction method, we borrow a 1 from a higher significant position when the minuend digit is
smaller than the corresponding subtrahend digit.

When subtraction is implemented with digital hardware, this method is found to be less efficient than the
method that uses complements.
Subtractions:
The subtraction of two n-digit unsigned numbers M-N(N≠0) in base r can be done as follows:

1. Add the minuend M to the r’s complement of the subtrahend N.


This performs M+(rn-N) = M-N+rn.
2. If M≥N, the sum will produce an end carry rn which is discarded, and what is left is the result M-N.

3. If M<N, the sum does not produce an end carry and is equal to rn-(N-M), which is the r’s
complement of (N-M). To obtain the answer in a familiar form, take the r’s complement of the sum
and place a negative sign in front.

Example: (1) Subtract 72532-13250 = 59282

M = 72532
10’s complement of N = 86750
159282

Discard the end carry 105, Answer = 59282

10’s complement of 13250 is


99999
13250
86749
___+1
86750
(2) Consider an example with M<N

Subtract 13250 – 72532


M = 13250
10’s complement of N = 27468
40718
There is no end carry 10’s complement of 40718
99999
40718
59281
+1
59282
Subtraction with complements is done with binary numbers in a similar manner using the same procedure
outlined above.

Ex: X = 1010100 and Y = 1000011 Perform X-Y and Y-X using 2’s complements.

X-Y? X = 1010100
2’s complement of Y = 0111101
10010001

Discard the end carry at 28, Answer is 0010001

Y-X? Y = 1000011
2’s complement of X = 0101100
1101111

1’s of X = 0101011
+1
0101100
There is no end carry. Answer is (-0010001) = (2’s complement of 1101111)

Note: When subtracting with complements, the negative answer is recognized by the absence of the end
carry and the complemented result.

Signed number representation:

Positive number: When an integer binary number is positive, the sign is represented by 0 and the
magnitude by a positive binary number. (Signed-magnitude representation)

Negative number: When the number is negative, the sign is represented by 1 but the rest of the
number (magnitude or value) may be represented by its one of three possible ways:

1. Signed – magnitude representation


2. Signed – 1’s complement representation
3. Signed – 2’s complement representation

Example: Consider the signed number +14 stored in an 8-orbit register.

+14 0 0001110
Sign value (magnitude) bits
bit
Consider the signed number -14: represented in three different ways.

-14 1 0001110 (Signed-magnitude representation)


-14 1 1110001 (Signed – 1’s complement representation)
-14 1 1110010 (Signed – 2’s complement representation)
Sign Value (magnitude) bits
bit

Note: The signed – magnitude system is used in ordinary arithmetic but it is awkward when employed in
computer arithmetic. Therefore, the signed – complement is normally used.

Signed-1’s complement representation:


Limitation: The 1’s complement imposes difficulties because it has two representations of 0(+0 and -0).
It is seldom used for arithmetic operations except in some older computers.
Usage:
The 1’s complement is useful as a logical operation since the change of 1 to 0 (or) 0 to 1 is
equivalent to a logical complement operation.

Signed – 2’s complement representation:


It is exclusively used for signed binary arithmetic operation (Addition, subtraction, multiplication etc)

Normal Arithmetic Addition: The addition of two numbers in the signed magnitude system follows the
rules of ordinary arithmetic.

If the signs are the same, we add the two magnitudes and give the sum the common sign.
+25+37 => +62
If the signs are different, we subtract the smaller magnitude from the larger and give the result the
sign of the larger magnitude.
(+25)+(-37) => -12
Note: This is a process that requires the comparison of the signs and the magnitudes and then performing
either addition (or) subtraction.
Arithmetic addition for signed numbers (2’s complement addition):
By contrast, the rule for adding numbers in the signed-2’s complement system does not require a
comparison or subtraction, only addition and complementation.

Procedure:
Add the two numbers, including their sign bits, and discard any carry out of the sign (leftmost) bit
position.
Note that negative numbers must initially be in 2’s complement and that if the sum obtained after the
addition is negative, it is in 2’s complement form.

Ex: +6 : 00000110 - 6 : 11111010 (2’s complement)


+13: 00001101 +13: 00001101
+19: 00010011 + 7 : 00000111

+6 : 00000110
-13: 11110011 (2’s complement form)
-7 : 11111001 (2’s complement form = > equivalent to 00000111)

-6 : 11111010 – 2’s comp. form


-13: 11110011 – 2’s comp. form
-19: 11101101 – 2’s comp. form

Arithmetic Subtraction for signed numbers (2’s complement subtraction):


1. Take the 2’s complement of the subtrahend (including sign bit) and add it to minuend (including the
sign bit).
2. A carry out of the sign bit position is discarded.

Note the fact that a subtraction operation can be changed to an addition operation if the sign of the
subtrahend is changed.
(+A) – (+B) = (+A) + (- B)
(+A) – (-B) = (+A) + (+ B)
Ex:
Consider the subtraction of (-6)-(-13) = (+7)
(-6) in 2’s complement form: 1 1111010
↑ ↑
Sign bit value bit

(-13) in 2’s complement form: 1 1110011


↑ ↑
Sign bit value bit

2’s complement of (-13) (subtrahend) = 00001101

(-6) : 11111010
2’s comp. of (-13): 00001101
100000111 = (+7)

End carry

Note: Binary numbers in the signed 2’s complement system are added and subtracted by the same basic
addition and subtraction rules as unsigned numbers. Therefore, computers used only one common hardware
circuit to handle both type of arithmetic.
Signed decimal numbers:
The representation of signed decimal numbers in BCD is similar to the representation of signed
numbers in binary.
Sign bits in decimal are 0 – for positive sign
9 – for negative sign
(1001) – 4 bit code
To perform arithmetic operations, the procedures developed for the signed 2’s complement system apply
also to the signed 10’s complement system for decimal numbers.

 Addition is done by adding all digits, including the sign digit, and discarding the end carry.
 Assume that all negative numbers are in 10’s complement form.

Ex: Consider the addition (+375)+(-240)(=+135)

(+375) : 0 375
10’s complement of (240) : 9 760
1 0 135

Discard the end carry, answer is (+135)

Note: Of course, the decimal numbers inside the computers must be in BCD, including the sign digit. The
addition is done with BCD adder. Many computers have special hardware to perform arithmetic calculation
directly with decimal numbers in BCD.

The subtraction of decimal numbers either unsigned or signed 10’s complement is the same as in the binary
case. Take the 10’s complement of the subtrahend and add it to the minuend.

Fixed-point representation:
Positive integers, including zero, can be represented as unsigned numbers. However, to represent negative
integers, we need a notation for negative values. (sign)

It is customary to represent the sign with a bit placed in the left most position of the number.
Sign bit equal to 0 – for positive (+)
Sign bit equal to 1 – for negative (-)

Binary Point: In addition to the sign, a number may have a binary (or decimal) point. The representation of
the binary point in a register is characterized by a position in the register.

Two ways of specifying the position of the binary point in the register:
1. By giving it a fixed position (or)
2. By employing a floating – point representation.

Fixed-Point method:
The fixed-point method assumes that the binary point is always fixed in one position. Two position
most widely used are:
1. A binary point in the extreme left of the register to make the stored number a fraction, and
2. A binary point in the extreme right of the register to make the stored number an integer.

In either case, the binary point is not actually present, but its presence is assumed from the fact that the
number stored in the register is treated as a fraction (or) as an integer.
Floating-point Representation:

It has two parts:

1. Mantissa => The first part represents a signed, fixed point number.
2. Exponent => The second part designates the position of the decimal (or binary) point.

The fixed-point mantissa may be a fraction or an integer.

Example:The decimal number +6132.789 is represented in floating point with a fraction and an exponent as
follows:

Fraction Exponent
+0.6132789 +04

The value of the exponent indicates that the actual position of the decimal point is four position to the right
of the indicated decimal point in the fraction.

It is equivalent to scientific notation +0.6132789×10+4

Floating-point is always interpreted to represent a number in the following form: (m×re)

Note: only the mantissa m and the exponent e are physically represented in the register (including their
signs). The radix r and the radix point position of the mantissa are always assumed.

A floating point binary umber is represented in a similar manner except that it uses base 2 for the exponent.

Example: The binary number +1001.11 is represented with an 8 orbit fraction and 6-bit exponent as
follows:

Fraction Exponent
0 1001110 000100

Sign bit

The fraction has a 0 in the leftmost position to denote positive. The binary point of the fraction follows the
sign bit but is not shown in the register.

The exponent has the equivalent binary number +4.


m×2e = +(.1001110)2×2+4

Note: A floating-point number is said to be normalized if the most significant digit of the mantissa is
nonzero

Ex: 350 – normalized 11010000


00035 – not normalized 00011010

Two main standard forms of floating-point numbers

1. ANSI – American national standard Institute


2. IEEE – Institute of Electrical and Electronic Engineers.
ANSI: 32 bit floating point numbers in byte forms.

Byte format:

Byte 1 Byte 2 Byte 3 Byte 4


SEEEE . MMMMMMMM MMMMMMMM MMMMMMMM
↑ ↑ ↑
Exponent Binary point mantissa(from byte 2 to byte 4)

S – sign of mantissa
E – Exponent Bits on 2’s complement
M - mantissa bits

Ex: 13 : 1101 => 0.1101×24


 00000100 11010000 . 00000000 00000000

-17 : -10001 => -0.10001×25


=> 10000101 10001000 . 00000000 00000000

-0.125 : -0.001 => -0.1×2-2


=> 11111110 10000000 . 00000000 00000000

Note: The number can be normalized by shifting it (three) position the left and discard leading zero.
Normalized numbers provide maximum possible precision for the floating-point number.

Exercises:
convert:
1. Binary to decimal: 101110, 1110101, 110110100
2. Decimal to binary: 1231, 673, 1998
3. 7562 to octal
1938 to hexadecimal
175 to binary
4. F3A7C2 to binary and octal
5. Show the value of all bits of a 12-bit register that hold the number equivalent to decimal 215 in (a)
binary, (b) BCO, (c) BCH, (d) BCD

6. Obtain 9’s complement: 12349876, 00980100


7. Obtain 10’s complement: 123900, 090639
8. Obtain 1’s and 2’s complement: 10101110, 10000001,
9. Perform the subtraction: with unsigned decimal numbers, with unsigned binary numbers
5250 – 1320
1753 – 8640
11010 – 10000
11010 – 1101

10. Perform the arithmetic operation


(+70)+(+80), and (-70)+(-80) with binary numbers in 2’s complement representation. Use 8-bits,
show that overflow occurs in both cases.
11. Perform (-630)+(+785) and (-630)-(+185) with decimal numbers using signed 10’s complement
representation for negative numbers.

You might also like