Number System Prepared by: Risala Tasin Khan PROFESSOR IIT
2 Base-N Number System Base N N Digits: 0, 1, 2, 3, 4, 5, …, N-1 Example: 1045 N Positional Number System Digit d o is the least significant digit (LSD). Digit d n -1 is the most significant digit (MSD).
3 Decimal Number System Base 10 Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 1045 10 Positional Number System Digit d is the least significant digit (LSD). Digit d n -1 is the most significant digit (MSD).
4 Binary Number System Base 2 Two Digits: 0, 1 Example: 1010110 2 Positional Number System B inary Dig its are called Bits Bit b o is the least significant bit (LSB). Bit b n-1 is the most significant bit (MSB).
5 Hexadecimal Number System Base 16 Sixteen Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Example: EF56 16 Positional Number System 0000 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F
6 Definitions nybble = 4 bits byte = 8 bits (short) word = 2 bytes = 16 bits (double) word = 4 bytes = 32 bits (long) word = 8 bytes = 64 bits 1K (kilo or “kibi”) = 1,024 1M (mega or “mebi”) = (1K)*(1K) = 1,048,576 1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824
Quantities/Counting (2 of 3) Decimal Binary Octal Hexa- decimal 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F
Conversion Among Bases The possibilities: Hexadecimal Decimal Octal Binary
Binary to Decimal Hexadecimal Decimal Octal Binary
Binary to Decimal Technique Multiply each bit by 2 n , where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results
Example 101011 2 => 1 x 2 = 1 1 x 2 1 = 2 0 x 2 2 = 0 1 x 2 3 = 8 0 x 2 4 = 0 1 x 2 5 = 32 43 10 Bit “0”
Fractions Binary to decimal pp. 46-50 10.1011 => 1 x 2 -4 = 0.0625 1 x 2 -3 = 0.125 0 x 2 -2 = 0.0 1 x 2 -1 = 0.5 0 x 2 = 0.0 1 x 2 1 = 2.0 2.6875
Decimal to Binary Hexadecimal Decimal Octal Binary
Decimal to Binary Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.
Multiplication Binary, two 1-bit values A B A B 1 1 1 1 1
Multiplication Binary, two n -bit values As with decimal values E.g., 1110 x 1011 1110 1110 0000 1110 10011010
43 Complements 1’s complement To calculate the 1’s complement of a binary number just “flip” each bit of the original binary number. E.g. 0 1 , 1 01010100100 10101011011
44 Complements 2’s complement To calculate the 2’s complement just calculate the 1’s complement, then add 1. 01010100100 10101011011 + 1= 10101011100
45 Complements Note the 2’s complement of the 2’s complement is just the original number N EX: let N = 01010100100 2’s comp of N = M = 10101011100 2’s comp of M = 01010100100 = N
46 Arithmetic Subtraction Borrow Method This is the technique you learned in grade school For binary numbers, we have 0 - 0 = 0 1 - 0 = 1 1 - 1 = 0 0 - 1 = 1 with a “borrow” 1
47 Binary Subtraction Note: A – (+B) = A + (-B) A – (-B) = A + (-(-B))= A + (+B) In other words, we can “subtract” B from A by “adding” –B to A. However, -B is just the 2’s complement of B, so to perform subtraction, we 1. Calculate the 2’s complement of B 2. Add A + (-B)