Assoc. Prof. Dr. Ahmet Turan ÖZCERİT
The base of numbers Conversion between number bases Arithmetic operations on different bases You will learn: 2
He/She can define the term of number bases 3 Computers use a number base other than base-10, namely binary Each data used and stored in computer represented in binary numbers Binary numbers are not easy to do arithmetic operations, so we use hex and octal numbers for the sake of simplicity All characters, images, audio and video samples are also presented in binary numbers Computers use a number base other than base-10, namely binary Each data used and stored in computer represented in binary numbers Binary numbers are not easy to do arithmetic operations, so we use hex and octal numbers for the sake of simplicity All characters, images, audio and video samples are also presented in binary numbers
He/She can define the term of number bases 4 N: Digit value d: Number digit R: Number radix(base) N=d n R n + d n-1 R n-1 + …+ d 2 R 2 + d 1 R 1 +d 0 R 0 (for integers) N=d n R n +d n-1 R n-1 +…+d 1 R 1 +d 0 R 0, d 1 R -1 + d 2 R -2 +…+ d n R -n (for real numbers) The number of digits in the R-based number system is R, the largest digit is R-1, and the least digit is 0. The largest number for n-digit is R n -1 and the number of different value for n-digit is R n N: Digit value d: Number digit R: Number radix(base) N=d n R n + d n-1 R n-1 + …+ d 2 R 2 + d 1 R 1 +d 0 R 0 (for integers) N=d n R n +d n-1 R n-1 +…+d 1 R 1 +d 0 R 0, d 1 R -1 + d 2 R -2 +…+ d n R -n (for real numbers) The number of digits in the R-based number system is R, the largest digit is R-1, and the least digit is 0. The largest number for n-digit is R n -1 and the number of different value for n-digit is R n
He/She can make operation on binary numbers 5 The largest digit in binary system R-1 => 2-1 => 1 The least digit in binary system is 0 Each radix in binary number systems is called BIT (BInary DigiT). The most significant bit (MSB) The binary number general form: B= d n 2 n + d n-1 2 n-1 + ……. + d d d 0 2 0, d d d n 2 -n The largest digit in binary system R-1 => 2-1 => 1 The least digit in binary system is 0 Each radix in binary number systems is called BIT (BInary DigiT). The most significant bit (MSB) The binary number general form: B= d n 2 n + d n-1 2 n-1 + ……. + d d d 0 2 0, d d d n 2 -n Binary SystemDecimal System
He/She can make operation on binary numbers 6 What is binary value of following binary number: B= 1*2 8 +0*2 7 +1* * * * * * *2 0 B= B= What is binary value of following binary number: , 1101 B= 1*2 8 +0*2 7 +1*2 6 +1*2 5 +0*2 4 +1*2 3 +1*2 2 +0*2 1 +1*2 0, 1* * * *2 -4 B= B= 365, What is binary value of following binary number: B= 1*2 8 +0*2 7 +1* * * * * * *2 0 B= B= What is binary value of following binary number: , 1101 B= 1*2 8 +0*2 7 +1*2 6 +1*2 5 +0*2 4 +1*2 3 +1*2 2 +0*2 1 +1*2 0, 1* * * *2 -4 B= B= 365,
He/She can make operation on octal numbers 7 Octal numbers are used to present binary numbers with 3-digit format The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7 O= d n 8 n + d n-1 8 n-1 + ……. + d d d 0 8 0, d d d n 8 -n Octal numbers are used to present binary numbers with 3-digit format The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7 O= d n 8 n + d n-1 8 n-1 + ……. + d d d 0 8 0, d d d n 8 -n BinaryOctal
He/She can make operation on hex numbers 8 Hex numbers are used to present binary numbers with 4-digit format The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F O= d n 16 n + d n-1 16 n-1 + ……. + d d d , d d d n 16 -n Hex numbers are used to present binary numbers with 4-digit format The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F O= d n 16 n + d n-1 16 n-1 + ……. + d d d , d d d n 16 -n BinaryHex BinaryHex A 1011B 1100C 1101D 1110E 1111F
He/She can convert number bases each other 9 The steps of converting of 117,86 10 decimal number into a binary number First, the integer part of the number is resolved then real part The steps of converting of 117,86 10 decimal number into a binary number First, the integer part of the number is resolved then real part DivisionRemainderResult 117/2 =581B 0 =1 58/2 = 29 0B 1 =0 29/2 =141B 2 =1 14/2 =70B 3 =0 7/2 =31B 4 =1 3/2 =1 1B 5 =1 1/2 =0 1B 6 =1 MultiplyIntegerResult 0.86*2=1.72 1b 1 =1 0.72*2=1.44 1b 2 =1 0.44*2=0.88 0b 3 =0 0.88*2=1.76 1b 4 =1 0.76*2=1.52 1b 5 =1 0.52*2=1.04 1b 6 =1 0.04*2=0.08 0b 7 =0 (117,86) 10 = ( , ….) 2
He/She can convert number bases each other 10 Convert a real decimal number (0,513) 10 into an octal number OperationMultiplyIntegerResult 0.513* o 0 = * o 1 = * o 2 = * o 3 = * o 4 =1 (0,513) 10 ≅ (0,40651) 8
He/She can convert number bases each other 11 Convert a decimal number (214) 10 into a hex number OperationDivisionRemainderResult 214/16136O 0 =6 13/16013O 1 =D (214) 10 = (D6) 16 Convert a decimal number (423) 10 into a hex number OperationDivisionRemainderResult 423/16267O 0 =7 26/16110O 1 =A 1 1O 2 =1 (423) 10 = (1A7) 16
He/She can convert number bases each other 12 Convert a binary number (100.01) 2 into a decimal number = 1* * *2 0, 0* *2 -2 = 1* , 0 + 1* ¼ = , = (4,25) 10 Convert a binary number (100.01) 2 into a decimal number = 1* * *2 0, 0* *2 -2 = 1* , 0 + 1* ¼ = , = (4,25) 10
He/She can convert number bases each other 13 Converting a binary number ( ) 2 into an octal number For integer part; start from just after the dot towards to the leftmost digit and combine 3-bits as a group. Fill zeros if the group is less than 3-bit For real part; start from just after the dot towards to the rightmost digit and combine 3-bits as a group. Fill zeros if the group is less than 3-bit Converting a binary number ( ) 2 into an octal number For integer part; start from just after the dot towards to the leftmost digit and combine 3-bits as a group. Fill zeros if the group is less than 3-bit For real part; start from just after the dot towards to the rightmost digit and combine 3-bits as a group. Fill zeros if the group is less than 3-bit
He/She can convert number bases each other 14 Converting a binary number ( ) 2 into a hex number For integer part; start from just after the dot towards to the leftmost digit and combine 4-bit as a group. Fill zeros if the group is less than 4-bit For real part; start from just after the dot towards to the rightmost digit and combine 4-bit as a group. Fill zeros if the group is less than 4-bit.C E Converting a binary number ( ) 2 into a hex number For integer part; start from just after the dot towards to the leftmost digit and combine 4-bit as a group. Fill zeros if the group is less than 4-bit For real part; start from just after the dot towards to the rightmost digit and combine 4-bit as a group. Fill zeros if the group is less than 4-bit.C E
He/She can convert number bases each other 15 Converting an Octal number into a binary number Convert each digit into its 3-bit binary counterpart. Example ( ) 8 =( ) 2 Converting an octal number into a decimal number Multiply each digit’s value by radix and sum all terms Example (372.2) 8 = 3x x x x8 -1 = 3x64 + 7x8 + 2x1 +2x0.125 =(250.25) 10 Converting an Octal number into a binary number Convert each digit into its 3-bit binary counterpart. Example ( ) 8 =( ) 2 Converting an octal number into a decimal number Multiply each digit’s value by radix and sum all terms Example (372.2) 8 = 3x x x x8 -1 = 3x64 + 7x8 + 2x1 +2x0.125 =(250.25) 10
He/She can convert number bases each other 16 Converting an Octal number into a hex number Step1. Convert each digit into its 3-bit binary counterpart. Step2. Compose 4-bit groups Step3. Convert 4-bit into hex counterpart Integer part group direction. Real part group direction Example (5431) 8 = ( ? ) 16 Step1. ( ) 2 Step Step3. B 1 9 (5431) 8 = (B19) 16 Converting an Octal number into a hex number Step1. Convert each digit into its 3-bit binary counterpart. Step2. Compose 4-bit groups Step3. Convert 4-bit into hex counterpart Integer part group direction. Real part group direction Example (5431) 8 = ( ? ) 16 Step1. ( ) 2 Step Step3. B 1 9 (5431) 8 = (B19) 16
He/She can convert number bases each other 17 Converting an hex number into a binary number Convert each digit into its 4-bit binary counterpart. Example ( ) 16 =( ) 2 Converting an hex number into a decimal number Multiply each digit’s value by radix and sum all terms Example (372) 16 = 3x x x16 0 = 3x256+ 7x16 + 2x1 = = (881) 10 Converting an hex number into a binary number Convert each digit into its 4-bit binary counterpart. Example ( ) 16 =( ) 2 Converting an hex number into a decimal number Multiply each digit’s value by radix and sum all terms Example (372) 16 = 3x x x16 0 = 3x256+ 7x16 + 2x1 = = (881) 10
He/She can convert number bases each other 18 Converting an Hex number into a Octal number Step1. Convert each digit into its 4-bit binary counterpart. Step2. Compose 3-bit groups Step3. Convert 3-bit into octal counterpart Integer part group direction. Real part group direction Example (E0CA) 16 = ( ? ) 8 Step1. ( ) 2 Step2. ( ) 2 Step3. ( ) 8 (E0CA) 16 = (160312) 8 Converting an Hex number into a Octal number Step1. Convert each digit into its 4-bit binary counterpart. Step2. Compose 3-bit groups Step3. Convert 3-bit into octal counterpart Integer part group direction. Real part group direction Example (E0CA) 16 = ( ? ) 8 Step1. ( ) 2 Step2. ( ) 2 Step3. ( ) 8 (E0CA) 16 = (160312) 8
He/She can do arithmetic operations on various radix 19 0+0 =0 1+0 =1 1+1 =0 Carry= 0+0 =0 1+0 =1 1+1 =0 Carry= Carry
He/She can do arithmetic operations on various radix 20 0-0 =0 1-0 =1 1-1 =0 0-1 =1 borrow= 0-0 =0 1-0 =1 1-1 =0 0-1 =1 borrow=
He/She can do arithmetic operations on various radix 21 In digital electronics, it is easier to create adder than subtractor unit. M-N can be redefined as M+( r complement of N) N can be negated by 1’s complement but 1’s complement contain both +0 and -0. STEP-1: Convert subtraction operation into addition by using r complement STEP-2: a. If an extra carry is obtained at the end, discard it and the number is assumed as positive. b. If no carry is obtained, apply r complement to result and add 1 In digital electronics, it is easier to create adder than subtractor unit. M-N can be redefined as M+( r complement of N) N can be negated by 1’s complement but 1’s complement contain both +0 and -0. STEP-1: Convert subtraction operation into addition by using r complement STEP-2: a. If an extra carry is obtained at the end, discard it and the number is assumed as positive. b. If no carry is obtained, apply r complement to result and add 1
He/She can do arithmetic operations on various radix 22 Example with extra carry: N can also be negated by 2’s complement (1’s complement+1) M= , N= M-N=? M-N = M+(-N) = M+ (2’s complement of N) = M+ (1’s complement+1) 2 1’s Complement of N= ( ) 2 2s complement of N (1’s complement of N + 1) = ( ) MSB is discarded, the result= ( ) 2
He/She can do arithmetic operations on various radix 23 Example without extra carry: M= (68) 10 N = (84) 10 M-N =? for 2’s complement 1’s complement of N= ( ) 2’s complement of N (1’s complement of N + 1) = ( ) No carry (-16) 10 1s comp ( ) 2 (-16) 10
He/She can do arithmetic operations on various radix
He/She can do arithmetic operations on various radix 25