260 likes | 465 Views
Introduction to Computers and Programming (CSC103) – Lecture 1b. Dr. Muhammad Kamran Email: m.kamran.nuces@gmail.com Comsats Institute of Information Technology [ www. ciitwah .edu.pk ]. Text Book Introduction to Computer Science, 2 nd Edition ITL Education Solutions Limited
E N D
Introduction to Computers and Programming(CSC103) – Lecture 1b Dr. Muhammad Kamran Email: m.kamran.nuces@gmail.com Comsats Institute of Information Technology [www.ciitwah.edu.pk]
Text Book Introduction to Computer Science, 2nd Edition ITL Education Solutions Limited Published by Pearson
Topics to be Covered • Number Systems
Number Systems • Four common number systems • Decimal – 10 Digits • Binary – 2 Digits • Octal – 8 Digits • Hexadecimal – 16 Digits • ‘Base’ ,also called ‘Radix’, represents the total number of digits of a system • We use a subscript to indicate the ‘base’ or the ‘radix’. For example, • (56)10 , (00110)2 , (253)8 , (AF14)16 Humans mostly use this
Some Key Points to Remember We can convert numbers from any number system to any other number system Octa Binary Hexadecimal Octa Decimal Hexadecimal Decimal Binary OR Decimal Binary Hexadecimal Octa Decimal Binary OR Octa Hexadecimal Easiest conversion is Octa, Binary, Hexadecimal intoDecimal
Decimal Number System • Comprises of ten digits • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • Lowest 0……highest 9, one less than the base of 10 • Examples are 667, 20, 2, -56 etc Remember!! Every position represents a power of the base = 4764510 + + + +
Binary Number System • Comprises of only two digits • 0 and 1 • Lowest – 0, highest - 1, one less than the base 2 • Computers use binary system internally • Not efficient for representation of fractions (available fractions include ½, ¼, 1/8, 1/16…) Remember!! Every position represents a power of the base = 2210 + + + +
Octal Number System • Comprises of eight digits • 0, 1, 2, 3, 4, 5, 6, 7 • Lowest - 0, Highest – 7 Remember!! Every position represents a power of the base + + + + = 596910
Hexadecimal Number System • Comprises of 16 digits • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F • Lowest – 0, highest – F which has a value equivalent to decimal 15 (one less than the base of 16) • It is used in low-level software and assembly language development Remember!! Every position represents a power of the base = 694510 + + +
Different Conversions Now we are left with Binary, Octa and Hexadecimal conversions Binary, Octa, Hexadecimal into Decimal (we did these on slides 7,8,9) Decimal into Binary, Octa, Hexadecimal ( we will do in next lecture) Coming up in next few slides Good News Octa into Hexadecimal and vice versa (last topic for today) We have a shortcut method for Binary to Octa, Hexadecimal and vice versa conversions
Conversion of Binary to Octa & Hex Lets prove it by converting all 3 into decimal !! Recall conversion method from slides 7,8,9
Conversion of Hex to Octa and Vice Versa • Follow these two rules; • Convert the number into Decimal ( as we did in slides 7,8,9) • Then convert the obtained Decimal number into the other number system Hexadecimal Number Octa Number Decimal Number
Decimal to Binary, Octa, Hexadecimal • Write down the base • Start dividing the decimal number by the ‘base’ • Keep recording remainders until no more division is possible • The remainders, arranged in reverse order, form the answer Lets see One example of each in next 3 slides
1. Decimal to Binary Conversion • Conversion of 4610 into Binary Base = 2 is Divisor Decimal No. is dividend 4610 = 1011102 LSB MSB
2. Decimal to Octa Conversion • Conversion of 453210 into Octa Base = 8 is Divisor Decimal No. is dividend 453210 = 106648 LSB MSB
3. Decimal to Hexadecimal Conversion • Conversion of 5047610 into Hexadecimal Base = 16 is Divisor Decimal No. is dividend 5047610 = C52C16 LSB MSB
Hexadecimal to Octa and Reverse • Two Possible Ways of doing it Hexadecimal Hexadecimal Decimal Binary Octa Octa
Now lets do some Binary Arithmetic Binary Addition Binary Subtraction (Borrow Method & Complement’s Method)
Binary Addition • Addition table for binary digits • 0 0 1 1 • + 0 + 1 + 0 + 1 • 0 1 1 10 • sum bit • carry bit
Multi-bit Binary Addition • When adding binary numbers if a carry is generated, it is carried one position to the left, just as in decimal arithmetic • Example 11 1 1 • X 173 1 0 1 0 1 1 0 1 • + Y 44 0 0 1 0 1 1 0 0 • 217 1 1 0 1 1 0 0 1
Binary Subtraction • Subtraction table for binary digits • 0 0 1 1 • - 0 - 1 - 0 - 1 • 0 1 1 0 • with borrow from the next column
Multi-bit Binary Subtraction • We will subtract using binary equivalents and prove the following; 2110 – 1410 = 710 Borrow 2110 1410 - 24 + 23 + 22 + 21 + 20 = 710