0% found this document useful (0 votes)
8 views23 pages

chapter five (1)

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

chapter five (1)

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

CHAPTER TWO:

Number Systems and Codes


 Besides the decimal and binary number systems,
the octal (radix 8) and hexadecimal (radix 16) are
important in digital computer.
Binary number
 Only one of two possible values (0 or 1) per digit
Reliably transported among computer system
components
 Can be processed by two–state electrical devices
relatively easy to design and fabricate
• Correspond directly with values in Boolean logic
Hexadecimal
• Uses 16 as its base
• Has a range of digits from 0 to 9, A,B,C,D,E,F
• Compact; its advantage over binary notation: 4 bits in binary is one
digit in Hexadecimal.
• Often used to designate memory addresses
Octal Notation

– Uses base 8 numbering system


– Has a range of digits from 0 to 7
– 3 bits in binary is one digit in Octal .
•The conversion from and to binary, octal, and hexadecimal representation plays an
important part in digital computers.
•The conversion from binary to octal is easily
accomplished by partitioning the binary number into groups of three bits each starting
from right to left and adding leading 0’s if necessary for the last group .
The corresponding octal digit is then assigned to each group of bits
•The string of digits so obtained gives the octal equivalent of the binary number

Conversion from binary to hexadecimal is similar except that the binary bits are divided into
groups of four starting from right to left and adding leading 0’s if necessary for the last
group.
The corresponding hexadecimal digit is then assigned to each group of bits
and the string of digits so obtained gives the hexadecimal equivalent of the binary number.
Complements
Complements are used in digital computers for simplifying the
subtraction operation and negative number representation.
Two types of complements for each base-r system
- r’s complement and r-1’s complement
- For binary numbers, when r= 2, the complements are 2’s
complement or 1’s complement
- For decimal numbers, r = 10, 10’s complement or 9’s complement

(r-1)’s complements of a number N with n digits is given by


(rn-1)-N, where r is the base of that number system.
r=10, r-1=9, 9’complements of N is (10n-1)-N
Ex) the 9’s complements of 546700 is 999999-546700 = 453299
For binary number that is when r=2 the (r-1)’s is r-1=1
1’complements of N with n digits is given by (2n-1)-N.
An alternate and easy way to find the 1's complement is to simply take
the bit by bit complement of the binary number.
Ex) the 1’s complements of 1011000 is 0100111.
the 1’s complements of 0101101 is 1010010.
The r’s complements of an n-digit number N is given by rn-N for N≠0
And it is 0 for N=0.
But rn-N=[(rn-1)-N]+1 That is The r’s complements is obtained by adding
1 to the (r-1)’s complements.
The 2’s complements of 1101100 is 0010100
The 2’s complements of 0110111 is 1001001
• The first the 1’s complement of 1101100 is 0010011 and then add 1
to it. 0010011
• 1
• 0010100
Fixed point Representation
 Positive numbers and zero can be represented as unsigned
numbers. But We need a representation for negative numbers.
 To represent a sign (+ or –) we need exactly one more bit of
information, because 1 binary digit gives 2 1 = 2 elements which
is exactly what is needed to represent the two signs + or -.
Since computers use binary numbers, by convention, the most
significant bit is interpreted as a sign bit:
s an–2  a2a1a0
where:
s = 0 for Positive numbers
s = 1 for Negative numbers
and the ai ‘s are either 0 or 1 to represent the magnitude of the
number in some form.
Signed Integer Representations
•We have three ways of representing signed integers.
–Signed-Magnitude – here the n – 1 digits are interpreted
as a positive magnitude. And the most significant bit is
used to represent a sign bit.
– Signed-Complement – here the digits are interpreted as
the rest of the complement of the number.
•Use fixed-length representation, but no separate sign bit
•There are two possibilities here:
• Signed 1's Complement
– Uses 1's Complement Arithmetic
• Signed 2's Complement
– Uses 2's Complement Arithmetic
Signed magnitude Integers
• Use fixed length binary representation
• Use left-most bit (called most significant bit or MSB) for sign:
0 for positive
1 for negative
• Example: in a 8 bit +18ten = 00010010two
- 18ten = 10010010two
• negative number are obtained by only complementing the sign bit.
• Disadvantages
– Sign and magnitude bits should be differently treated in arithmetic
operations.
– Addition and subtraction require different logic circuits.
– “Zero” has two representations:
+0ten = 00000000two
- 0ten = 10000000two
– Ex: assume 6 bit registers

– 1910 = 0100112 = 13HEX = 23OCT

– -1910  1910 = 0100112 therefore

• Signed magnitude: -1910 = 1100112


• By complementing the sign bit (from 0 to 1)
• 1’s complement: -1910 = 1011002
– by taking the 1’s complement of 010011

• 2’s complement: -1910 = 1011012


• Signed 2’s Complement Arithmetic
– Addition:
1. Add the numbers including the sign bits,
discarding a carry out of the sign bits
2. If the sign bits were the same for both
numbers and the sign of the result is different, an
overflow is said to occurred.
3. The sign of the result is computed in step 1.
• For n-digit, unsigned numbers M and N, find M  N in base 2:
– Add the 2's complement of the subtrahend N to the minuend
M:
M + (2n  N) = M  N + 2n
– If M  N, the sum produces end carry of 2n which is discarded
then M - N remains.
– If M < N, the sum does not produce an end carry and, from
above equation it is equal to 2n  ( N  M ) that is the 2's
complement of ( N  M). Note: when M<N, M-N=-(N-M)
– Hence, To obtain the result  (N – M) , take the 2's complement
of the sum (M + (2n  N) )and place a  to its left.
– The negative answer is recognized by the absence of the end
carry.
Unsigned 2’s Complement Subtraction Example 1

• Find 010101002 – 010000112

01010100 01010100
– 01000011 + 10111101
00010001
• The carry of 1 which will be discarded indicates that
no correction of the result is required. Hence the
answer is 00010001
• Find 010000112 – 010101002

01000011 01000011
– 01010100 + 10101100
11101111

• The carry of 0 indicates that a correction of the


result is required.
11101111 —00010000 1’s complement
00010000 + 1 =00010001 2’s complement
• Hence the final Result is – (00010001)
• Example 1: 1101
+ 0011
Result is 0000
– The carry out of (1) in the MSB is discarded.
• Example 2: 1101
- 0011
now find the 2’s Complement of 0011 which is 1101 and this
to 1101 add.
1101
1101
Result is 1010
The carry out of (1) in the MSB is discarded
How to find the decimal representation of a 2’scomplement
number
Step 1: Look at the most significant bit. If it’s 0, then treat it like regular
binary number and convert it to its decimal form. If 1, then go to
Step 2
Step 2: For a negative number n, find its 2’s complement n’.
Now, n’ = -n that is n’ is positive. And n = - n’
Find the decimal representation of n’. Let this be d.
Then, the decimal representation of n is -d.
• Example:
– What is 10010111? (Assume that 10010111 is in 2’s
complement representation)
– Most significant bit is 1. Therefore, take its 2’s
complement 10010111 which is 01101001.
– This number in decimal is 105.
– Therefore, 100101112c = -10510
Overflow
• When two numbers of n digits each are added and the sum
occupies n+1 digits, we say an over flow occurred.
• Overflow in unsigned addition:
– can be detected when the Last carry-out is 1 in the addition
process. That can occur when the sum is to big to represent.
• For 2’s complement, or in a signed addition
– Overflow has occurred if the sum of two positive numbers is
negative, or the sum of two negative numbers is positive. because
the sign bit has no place to be represented.
– But, For 2’s complement addition and subtraction, last carry-out
being 1 doesn’t necessarily mean overflow has occurred. Because
when two signed numbers are added , the sign bit is treated as
part of the number and the end carry does not indicate an over
flow.
• If the two operands are representable in n bits, then when can
overflow occur?
– positive + positive? Yes
– negative + negative? Yes
– positive + negative?
• No  if the two inputs are legal, the output must be
– negative + positive?
• No  same reason as above
Floating-Point Representation

Floating point
Fixed point
Normalized and UNNormalized
• A floating point number is said to be normalized if the number
after the radix point is a non-zero that is, it is not a ‘0’ value.
• Unnormalized floating number is when the number after the
radix point is ‘0’.
• Example:
 normalized
 unnormalized
 unnormalized

 normalized
Normalization Process
• Normalization is the process of deleting the zeroes until a non-zero value is detected.
■ A rule of thumb:
– moving the radix point to the right  subtract exponent
– moving the radix point to the left  add exponent

Floating Point Format for Binary Numbers


• General form:
In binary:

• Transform –33.625 to floating point word using the following format


(radix 2): I bit for sign, 4 bit for the exponent and 12 bit for the
mantissa.

You might also like