280 likes | 513 Views
Numbering Systems. Lecture1. Number Systems and Arithmetic’s. Notes: The decimal number system is said to be of Base (Radix), 10 because it uses 10 digits The Binary number system is said to be of Base (Radix), 2 because it uses 2 digits
E N D
Numbering Systems Lecture1
Number Systems and Arithmetic’s Notes: The decimal number system is said to be of Base (Radix), 10 because it uses 10 digits The Binary number system is said to be of Base (Radix), 2 because it uses 2 digits The Octal number system is said to be of Base (Radix), 8 because it uses 8 digits The Hexadecimal number system is said to be of Base (Radix), 16 because it uses 16 digits
1-2 Radix –R Representation To convert any number with radix R to decimal numbering system we apply the following formula
Conversion of Decimal To ANY Base ( R) Integer Parts: Divide Number N by base R until quotient is 0. Remainder at EACH step is a digit in base R, from Least Significant digit to Most Significant digit. Fraction Part: Multiply the fraction number M by the base ( Radix) R, and collect the resulting integer , starting with most significant digit ( MSD)
1-2 Conversion From Decimal to Binary I- Integer Parts : Modulo division of decimal integer by 2 to get each bit , starting with (Least Significant Bit (LSB) ) Example : Convert the following decimal numbers to Binary numbers 1- (29)10 2-(53)10 3-(41)10 1: Division Remainder 29/2 1 LSB 14/2 0 7/2 1 3/2 1 1/2 1 MSB 0 (29)10 =(11101)2 2: (53)10 Division Remainder 53/2 1 LSB 26/2 0 13/2 1 6 /2 0 3 /2 1 1 /2 1 MSB 0 (53)10 =(110101)2
3 : (41)10 41/2 1 LSB 20/2 0 10/2 0 5 /2 1 2 /2 0 1 /2 1 MSB 0 (41)10 =(101001)2 II: Fraction Parts : Multiplication decimal fraction by 2, and collect resulting integers, starting with (Most Significant Bit (MSB)) Example: Convert the following decimal number into binary Number 1: (0.828125 )10 0.828125 x2 = 1+ 0.65625 1 MSB 0.65625 x 2 = 1+ 0.3125 1 0.3125 x 2 = 0+ 0.625 0 0.625 x 2 = 1+ 0.25 1 0.25 x 2 = 0+ 0.5 0 0.5 x 2 = 1+ 0 1 LSB (0.828125)10 =(0.110101)2
2: (41. 625 )10 =(41)10 + (0.625 )10 from the above example (41)10 is represented by (101001)2 while (0.625 )10 is 0.625 x 2 = 1+ 0.25 1 MSB 0.25 x 2 = 0+ 0.5 0 0.5 x 2 = 1+ 0 1 LSB (0.625 )10 = (0.101)2 so (41. 625 )10 = (101001.101)2
1-4 Binary To Hexadecimal Conversion : Each Hex digit represents 4 bits. To convert a Hex number to Binary, simply convert each Hex digit to its four bit value.
1-5 Conversion from decimal numbering system to hexadecimal Numbering System • Integer Parts : Modulo division of decimal integer by 16 to get each digit , starting with (Least Significant digit (LSD) ) • Example : Convert the following decimal numbers to Hexadecimal numbers • 1- (29)10 2-(53)10 3-(32)10 4-(41)10 • 1: Division Remainder • 29/16 D LSD • 1 /16 1 MSD • 0 • (29)10 =(1D)16 • 2: (53)10 Division Remainder • 53/16 5 LSD • 3/16 3 MSD • 0 • (53)10 =(35)16 • 3: (32)10Division Remainder • 32/16 0 LSD • 2/16 2 MSD • 0 • (53)10 =(20)16
4: (41)10Division Remainder 41/16 9 LSD 2/16 2 MSD 0 (53)10 =(29)16 HW: (128)10=( )16 (267)10=( )16
II: Fraction Parts : Multiplication decimal fraction by 16, and collect resulting integers, starting with (Most Significant Digit (MSD)) Example: Convert the following decimal number into Hexadecimal Number 1: (0.828125 )10 0.828125 x16 = 13+ 0.25 D MSD 0.25 x 16 = 4+0 4 LSD (0.828125)10 =(0.D4)16 2: (0.75)10 0.75*16=12+0 C 0*16= =0 (0.75)10=(0.C)16
1-7 Conversion from decimal numbering system to Octal Numbering System • Integer Parts : Modulo division of decimal integer by 8 to get each digit , starting with (Least Significant digit (LSD) ) • Example : Convert the following decimal numbers to octal numbers • 1- (29)10 2-(53)10 3-(32)10 4-(41)10 • 1: Division Remainder • 29/8 5 LSD • 3/8 3 MSD • 0 • (29)10 =(35)8 • 2: (53)10 Division Remainder • 53/8 5 LSD • 6/8 6 MSD • 0 • (53)10 =(65)8 • 3: (32)10Division Remainder • 32/8 0 LSD • 4/8 4 MSD • 0 • (53)10 =(40)8
II: Fraction Parts : Multiplication decimal fraction by 8, and collect resulting integers, starting with (Most Significant Digit (MSD)) Example: Convert the following decimal number into Hexadecimal Number 1: (0.828125 )10 0.828125 x8 = 6+ 0.625 6 MSD 0.625 x 8 = 5+0 5 LSD (0.828125)10 =(0.65)8 2: (0.75)10 0.75*8=6+0 6 0*8= =0 (0.75)10=(0.6)8
Binary Arithmetic 1- Binary Addition: Example: 1111 0100 Carries 0000 0010 Carries 0011 1011 1011 1001 + 0111 1010 + 0100 0101 _________ _________ 1011 0101 1111 1110 1111 0000 Carries 1110 0000 0000.0001 Carries 1111 1001 0101 1000 1001.1001 + 0100 1000 + 0011 0011 0100.01 ---------------- ----------------------------- 1 0100 0000 1000 1011 1101.1101
2- Binary Subtraction I- Using 2’s complement: 1:- Add the 2’s complement . 2:- if the last carry =1 then the result is positive disregard the last carry, otherwise (carry=0) the result is negative , the number is in the 2’s complement form Example 1: 3 11 11 11 -2 -10 01+1 + 10 --- ----- ------- ------- 1 1 01 carry =1 result positive =01
Example 2: 9 1001 1001 1001 - 5 -0101 1010+1 + 1011 ------- --------- ----------- ---------- 4 1 0100 carry=1 positive result=0100 Example 3: 4 100 100 100 - 5 -101 010 +1 + 011 ----- ------- ---------- ------- -1 0 111 carry=0 Negative result (2’s complement form) 111 2’s comp. 000+1 - 001=-1 Example 4: 5 0101 0101 0101 - 9 - 1001 0110+1 + 0111 ------ --------- ----------- ---------- -4 0 1100 carry=0 negative result (2’s complement form) 1100 2’s comp. 0011+1 - 100= - 4
Example (3): Using 2’s complement, subtract 1010100 – 1000011 X – Y X = 1010100 2’s complement of Y = + 0111101 Sum = 10010001 Discard end carry 27 = - 10000000 Answer: X - Y = 0010001 Example (4): Using 2’s complement, subtract 1000011 – 1010100 Y – X Y = 1000011 2’s complement of X = + 0101100 Sum = 1101111 No end carry. Answer: Y – X - (2’s complement of 1101111) = -0010001
Bitwise Operators • & Bitwise AND1010 & 0011 = 0010 • | Bitwise inclusive OR1010 | 0011 = 1011 • ^ Bitwise exclusive OR1010 ^ 0011 = 1001 • << left shift 00000100 << 3 = 00100000 • >> right shift 00000100 >> 2 = 00000001
Floating Point Representation • Fixed point representation , Number x=(14.89)10 • floating point representation , Number x= m* r e m= mantissa (+,-) r -1≤ m <1 r = radix e= exponent =(+,-) integer Decimal point adjustment ( Normalization) Number Normalized Form ( 1456.56)10 0.145656E4 (0.000035)10 0.35E-4 (101.11)2 0.10111 E (11)2 (0.0011)2 0.11 E (- 10)2