COA Chapter 2
COA Chapter 2
Data Representation
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.
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.
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.
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.
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.
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.
(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)
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.
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.
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.
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:
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.
M = 72532
10’s complement of N = 86750
159282
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
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.
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:
+14 0 0001110
Sign value (magnitude) bits
bit
Consider the signed number -14: represented in three different ways.
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.
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.
+6 : 00000110
-13: 11110011 (2’s complement form)
-7 : 11111001 (2’s complement form = > equivalent to 00000111)
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
(-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.
(+375) : 0 375
10’s complement of (240) : 9 760
1 0 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:
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.
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.
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.
Note: A floating-point number is said to be normalized if the most significant digit of the mantissa is
nonzero
Byte format:
S – sign of mantissa
E – Exponent Bits on 2’s complement
M - mantissa bits
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