Module2_I_Number Systems and Arithmetic.pdf
Module2_I_Number Systems and Arithmetic.pdf
2
3
4
5 weight
6
7
8
9
DECIMAL NUMBERS
• Express the decimal number 47 as a sum of the values of each digit.
• Express the decimal number 568.23 as a sum of the values of each digit
BINARY NUMBERS
• The binary number system has two digits (bits).
• Largest decimal number = 2n- 1
0 The binary number system has a base of 2
• For example, with five bits (n = 5) you can
1 count from zero to thirty-one.
25 - 1 = 32 - 1 = 31
DEC BIN • With six bits (n = 6) you can count from
0 0 zero to sixty-three.
1 1 26 - 1 = 64 - 1 = 63
2 10 number of number of
bits combinations bits combinations
3 11 1 1 64 1.8E+19
2 3 128 3.4E+38
4 100 3 7 256 1.2E+77
5 101 4 15
5 31
6 110
6 63
7 111 7 127
8 1000 8 255
16 65535
9 1001 32 4E+09
THE WEIGHTING STRUCTURE OF BINARY NUMBERS
• LSB (least significant bit)
• MSB (most significant bit)
L1
BINARY-TO-DECIMAL CONVERSION
• Convert the binary whole number 1101101 to decimal.
EXAMPLE
EXAMPLE
Repeated Division-by-2 Method
converting the decimal number 12 to binary
Converting Decimal Fractions to Binary
Repeated Multiplication by 2
0.3125 to binary
BINARY ARITHMETIC
addition of 11 + 1
Binary Addition
In binary 10 - 1 = 1, not 9.
EXAMPLE
Subtract 011 from 101.
Half adder, Full adder:
Half subtractor, Full subtractor:
Binary Multiplication Binary Division
The four basic rules for multiplying bits are as follows: EXAMPLE
EXAMPLE
COMPLEMENTS OF BINARY NUMBERS
• The 1’s complement and the 2’s complement of a binary number are important
because they permit the representation of negative numbers.
• The method of 2’s complement arithmetic is commonly used in computers to handle
negative numbers.
you should be able to
• Convert a binary number to its 1’s complement
• Convert a binary number to its 2’s complement using either of two methods
Finding the 1’s Complement
EXAMPLE
EXAMPLE Find the 2’s complement of 10110010.
Find the 2’s complement of 10111000 using
the alternative method.
SIGNED NUMBERS
Table lists all possible four‐bit signed binary numbers in the three representations.
Note that all negative numbers have a 1 in the leftmost bit position; that is the way we distinguish them
from the positive numbers.
In the 2’s‐complement representation, there are
eight positive numbers, including one zero,
and eight negative numbers.
21
Range of Signed Integer Numbers
Unsigned Numbers: n-bit numbers
Total combination: 2n and the range is 0 to 2n-1
In the 2’s‐complement representation, there are eight positive numbers, including one zero, and eight negative
numbers. 2’s‐complement signed numbers, the range of values for n-bit numbers is:
In the signed‐magnitude and the 1’s‐complement representations, there are eight positive numbers and eight
negative numbers, including two zeros.
• 1’s‐complement signed numbers, the range of values for n-bit numbers is:
The left-most bit in a signed binary For example, the decimal number +25 is
number is the sign bit, which tells you expressed as an 8-bit signed binary
whether the number is positive or number using the sign-magnitude form as
negative.
A 0 sign bit indicates a positive number,
and a 1 sign bit indicates a negative -25 = 10011001
number.
SIGNED NUMBERS : Signed Magnitude
1’s Complement Form +25 = 00011001
-25 = 11100110 (1’s)
2’s Complement Form
+25 = 00011001
-25 = 11100111 (1’s+1 = 2’s)
EXAMPLE
Express the decimal number +39 as an 8-bit number in the sign-magnitude, 1’s complement, and 2’s complement forms.
+39 = 00100111
-39 = 10100111 (Signed magnitude)
-39 = 11011000 (1’s)
-39 = 11011001 (2’s)
THE DECIMAL VALUE OF SIGNED NUMBERS
Sign-Magnitude Determine the decimal value of this signed binary number
expressed in sign-magnitude: 10010101.
1’s Complement EXAMPLE Determine the decimal values of the signed binary
numbers expressed in 1’s complement:
(a) 00010111 (b) 11101000
1 Byte = 8 bits
1 Nibble = 4 bits
(a) 00010111 (b) 11101000
No need to make
any changes to
answer. Answer
obtained is the
final result.
ARITHMETIC OPERATIONS WITH BINARY SIGNED NUMBERS (2’S Complement)
Addition
The two numbers in an addition are the addend and the augend. The result is the sum.
There are four cases that can occur when two signed binary numbers are added.
1. Both numbers positive
2. Positive number with magnitude larger than negative number
3. Negative number with magnitude larger than positive number
4. Both numbers negative
➢ If there is a carry in final sum, the final carry bit is discarded. The sum is positive and therefore in
true (uncomplemented) binary.
➢ If there is no carry in final sum, the sum is negative and therefore in 2’s complement form
Arithmetic Addition using signed‐2’s‐complement
Rule: The addition of two signed binary numbers with negative numbers represented in
signed‐2’s‐complement form is obtained from the addition of the two numbers, including their sign bits.
A carry out of the sign‐bit position is discarded.
In each of the four cases, the operation performed is addition with the sign bit included. Any carry out of the
sign‐bit position is discarded, and negative results are automatically in 2’s‐complement form.
31
Arithmetic Addition using signed‐2’s‐complement
Overflow Condition: In order to obtain a correct answer, we must ensure that the result has a sufficient number of bits to
accommodate the sum. If we start with two n‐bit numbers and the sum occupies n + 1 bits, we say that an overflow occurs.
Overflow is indicated by incorrect sign bit.
Overflow is a problem in computers because the number of bits that hold a number is finite, and a result that exceeds the
finite value by 1 cannot be accommodated.
In the above example, the sum 183 requires eight magnitude bits. Since there are seven magnitude bits in the
numbers (and one sign bit), there is a carry into the sign bit which produces the overflow indication.
33
Arithmetic Subtraction using 2’s complement
Rule: Take the 2’s complement of the subtrahend (including the sign bit) and add it to the minuend (including the
sign bit). A carry out of the sign‐bit position is discarded.
34
Thank you !!!