Instructor: Tim Dosen DDAK Slide By: Erdefi Rakun: Fasilkom UI
Instructor: Tim Dosen DDAK Slide By: Erdefi Rakun: Fasilkom UI
Introduction 3
N bits can represent up to 2N values.
Examples:
2 bits represent up to 4 values (00, 01, 10, 11)
3 bits rep. up to 8 values (000, 001, 010, …, 110, 111)
4 bits rep. up to 16 values (0000, 0001, 0010, …., 1111)
Introduction 4
A weighted-positional number system
• Base or radix is 10 (the base or radix of a number system is
the total number of symbols/digits allowed in the system)
• Symbols/digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
• Position is important, as the value of each symbol/digit is
dependent on its type and its position in the number
• Example, the 9 in the two numbers below has different
values:
• (7594)10 = (7 × 103) + (5 × 102) + (9 × 101) + (4 × 100)
• (912)10 = (9 × 102) + (1 × 101) + (2 × 100)
• In general, (a a … a . f f … f ) =
n n-1 0 1 2 m 10
(an x 10n) + (an-1x10n-1) + … + (a0 x 100) +
(f1 x 10-1) + (f2 x 10-2) + … + (fm x 10-m)
Introduction 5
• Weighing factors (or weights) are in powers of 10:
… 103 102 101 100 . 10-1 10-2 10-3 …
• To evaluate the decimal number 593.68, the digit
in each position is multiplied by the
corresponding weight:
5×102 + 9×101 + 3×100 + 6×10-1 + 8×10-2
= (593.68)10
Introduction 6
• Binary (base 2)
Weights in powers of 2
Binary digits (bits): 0, 1
• Octal (base 8)
Weights in powers of 8
Octal digits: 0, 1, 2, 3, 4, 5, 6, 7.
• Hexadecimal (base 16)
Weights in powers of 16
Hexadecimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
• Base/radix R:
Weights in powers of R
Introduction 7
In some programming languages/software, special
notations are used to represent numbers in certain
bases
• In programming language C
Prefix 0 for octal. E.g.: 032 represents the octal number (32)8
Prefix 0x for hexadecimal. E.g.: 0x32 represents the hexadecimal
number (32)16
• In PCSpim (a MIPS simulator)
Prefix 0x for hexadecimal. E.g.: 0x100 represents the
hexadecimal number (100)16
• In Verilog, the following values are the same
8’b11110000: an 8-bit binary value 11110000
8’hF0: an 8-bit binary value represented in hexadecimal F0
8’d240: an 8-bit binary value represented in decimal 240
Introduction 8
• Review of information representation
• Base conversion
• Binary arithmetic operations
• Negative numbers
• Useful for Base Conversion
572.68 =
2A.816 =
341.245 =
2-6. Convert each of the decimal numbers in question 2-5 above to septimal (base 7)
with at most six digits in the fractional part rounded to six places.
2-7. Convert each of the decimal numbers in question 2-5 above to octal (base 8)
with at most four digits in the fractional part rounded to four places.
2-8. Convert each of the decimal numbers in question 2-5 above to hexadecimal
(base 16) with at most two digits in the fractional part rounded to two places.
Introduction 25
Given two binary digits (X,Y), a carry in (Z) we get the
following sum (S) and carry (C):
Carry in (Z) of 0: Z 0 0 0 0
X 0 0 1 1
+Y +0 +1 +0 +1
CS 00 01 01 10
Carry in (Z) of 1: Z 1 1 1 1
X 0 0 1 1
+Y +0 +1 +0 +1
CS 01 10 10 11
Introduction 26
• Extending this to two multiple bit examples:
Carries 0 0
Augend 01100 10110
Addend + 10001 + 10111
Sum
Introduction 27
• Given two binary digits (X,Y), a borrow in (Z) we
get the following difference (S) and borrow (B):
• Borrow in (Z) of 0: Z 0 0 0 0
X 0 0 1 1
-Y -0 -1 -0 -1
BS 00 11 01 00
• Borrow in (Z) of 1: Z 1 1 1 1
X 0 0 1 1
-Y -0 -1 -0 -1
BS 11 10 00 11
Introduction 28
• Extending this to two multiple bit examples:
Borrows 0 0
Minuend 10110 10110
Subtrahend - 10010 - 10011
Difference
• Notes:
The 0 is a Borrow-In to the least significant bit. If the
Subtrahend > the Minuend, interchange and append a – to the
result.
Introduction 29
The binary multiplication table is simple:
0∗0=0 | 1∗0=0 | 0∗1=0 | 1∗1=1
Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier × 101
Partial Products 1011
0000-
+ 1011--
Product 110111
Introduction 30
QUICK REVIEW QUESTIONS (1)
Introduction 31
100110 Quotient
Divisor 100010 100101010 Dividend
- 1000
10
101
1010
- 1000
1010 Remainder
sign magnitude
-3 1101 +5 0101
+ -6 + 1010 + +6 + 0110
---- ------- ---- -------
-9 10111 +11 1011
---- ------- ---- -------
-2 1101 -3 1100
+ -5 + 1010 + -7 + 1000
---- ------ ---- -------
-7 10111 -10 10100
---- + 1 ---- + 1
------ -------
1000 0101
Number Systems and Codes 53
QUICK REVIEW QUESTIONS (5)
• DLD page 37
2-13. In a 6-bit 2’s complement binary number system, what is the decimal
value represented by (100100)2s?
a. -4 b. 36 c. -36 d. -27 e. -28
2-14. In a 6-bit 1’s complement binary number system, what is the decimal
value represented by (010100)1s?
a. -11 b. 43 c. -43 d. 20 e. -20
2-15. What is the range of values that can be represented in a 5-bit 2’s
complement binary systems?
a. 0 to 31 b. -8 to 7 c. -8 to 8 d. -15 to 15 e. -16 to 15
2-17. Assuming a 6-bit 2’s complement system, perform the following subtraction
operation by converting it into addition operation:
a. (011010)2s - (010000)2s
b. (011010)2s - (001101)2s
c. (000011)2s - (010000)2s
2-18. Assuming a 6-bit 1’s complement system, perform the following subtraction
operation by converting it into addition operation:
a. (011111)1s - (010101)1s
b. (001010)1s - (101101)1s
c. (100000)1s - (010011)1s
Number Systems and Codes 55
ADD SUBTRACT Magnitudes
Operation Magnit
udes A>B A<B A=B
(+A) + (+B) + (A + B)
(+A) + (-B) + (A – B ) - (B – A ) + (A – B )
(-A) + (+B) - (A – B ) + (B – A ) + (A – B )
(-A) + (-B) - ( A + B)
(+A) - (+B) + (A – B ) - (B – A ) + (A – B )
(+A) - (-B) + (A + B)
(-A) - (+B) - ( A + B)
(-A) - (-B) - (A – B ) + (B – A ) + (A – B )