IT101: INFORMATION TECHNOLOGY FUNDAMENTALS 1 Edited By Dr. Ahmed Abo-Bakr Information Technology Dept. Faculty of Computers & Information
NUMBER SYSTEMS
Common Number Systems SystemBaseSymbols Used by humans? Used in computers? Decimal100, 1, … 9YesNo Binary20, 1NoYes Octal80, 1, … 7No Hexa- decimal 160, 1, … 9, A, B, … F No
Quantities/Counting (1 of 3) DecimalBinaryOctal Hexa- decimal
Quantities/Counting (2 of 3) DecimalBinaryOctal Hexa- decimal A B C D E F
Quantities/Counting (3 of 3) DecimalBinaryOctal Hexa- decimal Etc.
Conversion Among Bases The possibilities: Hexadecimal DecimalOctal Binary
Quick Example = = 31 8 = Base
Decimal to Decimal (just for fun) Hexadecimal DecimalOctal Binary
=>5 x 10 0 = 5 2 x 10 1 = 20 1 x 10 2 = Base Weight
Binary to Decimal Hexadecimal DecimalOctal 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 => 1 x 2 0 = 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 = Bit “0”
Octal to Decimal Hexadecimal DecimalOctal Binary
Octal to Decimal Technique Multiply each bit by 8 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 => 4 x 8 0 = 4 2 x 8 1 = 16 7 x 8 2 =
Hexadecimal to Decimal Hexadecimal DecimalOctal Binary
Hexadecimal to Decimal Technique Multiply each bit by 16 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 ABC 16 =>C x 16 0 = 12 x 1 = 12 B x 16 1 = 11 x 16 = 176 A x 16 2 = 10 x 256 =
Decimal (Integer) to Binary Conversion Hexadecimal DecimalOctal Binary
Decimal (Integer) to Binary Conversion Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.
Decimal (Integer) to Binary Conversion DDivide the number by the ‘Base’ (=2) TTake the remainder (either 0 or 1) as a coefficient TTake the quotient and repeat the division Example: ( 13 ) 10 QuotientRemainder Coefficient Answer: (13) 10 = (a 3 a 2 a 1 a 0 ) 2 = (1101) 2 MSB LSB 13 / 2 = 61 a 0 = 1 6 / 2 = 30 a 1 = 0 3 / 2 = 11 a 2 = 1 1 / 2 = 01 a 3 = 1
Example = ? =
Decimal (Fraction) to Binary Conversion Decimal to decimal (just for fun) 3.14 =>4 x = x = x 10 0 =
Decimal (Fraction) to Binary Conversion Binary to decimal => 1 x 2 -4 = x 2 -3 = x 2 -2 = x 2 -1 = x 2 0 = x 2 1 =
Decimal (Fraction) to Binary Conversion MMultiply the number by the ‘Base’ (=2) TTake the integer (either 0 or 1) as a coefficient TTake the resultant fraction and repeat the operation Example: ( ) 10 IntegerFraction Coefficient Answer: (0.625) 10 = (0.a -1 a -2 a -3 ) 2 = (0.101) 2 MSB LSB * 2 = * 2 = 0. 5 a -2 = * 2 = 1. 0 a -3 = 1 a -1 = 1
Decimal (Fraction) to Binary Conversion Decimal to binary x x x x x x etc
Octal to Binary Hexadecimal DecimalOctal Binary
Octal to Binary Technique Convert each octal digit to a 3-bit equivalent binary representation
Example = ? =
Hexadecimal to Binary Hexadecimal DecimalOctal Binary
Hexadecimal to Binary Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation
Example 10AF 16 = ? A F AF 16 =
Decimal to Octal Conversion Hexadecimal DecimalOctal Binary
Decimal to Octal Conversion Technique Divide by 8 Keep track of the remainder
Decimal to Octal Conversion Example: ( 175 ) 10 QuotientRemainder Coefficient Answer: (175) 10 = (a 2 a 1 a 0 ) 8 = (257) / 8 = 217 a 0 = 7 21 / 8 = 25 a 1 = 5 2 / 8 = 02 a 2 = 2 Example: ( ) 10 IntegerFraction Coefficient Answer: (0.3125) 10 = (0.a -1 a -2 a -3 ) 8 = (0.24) * 8 = * 8 = 4. 0 a -2 = 4 a -1 = 2
Example = ? =
Decimal to Hexadecimal Hexadecimal DecimalOctal Binary
Decimal to Hexadecimal Technique Divide by 16 Keep track of the remainder
Example = ? = 4D = D
Binary − Octal Conversion Hexadecimal DecimalOctal Binary
Binary − Octal Conversion Technique Group bits in threes, starting on right Convert to octal digits
Example = ? =
Binary − Octal Conversion 8 = 2 3 Each group of 3 bits represents an octal digit OctalBinary Example: ( ) 2 ( ) 8 Assume Zeros Works both ways (Binary to Octal & Octal to Binary)
Binary − Hexadecimal Conversion Hexadecimal DecimalOctal Binary
Binary − Hexadecimal Conversion Technique Group bits in fours, starting on right Convert to hexadecimal digits
Example = ? B B = 2BB 16
Binary − Hexadecimal Conversion 16 = 2 4 Each group of 4 bits represents a hexadecimal digit HexBinary A1 0 B C D E F1 1 Example: ( ) 2 ( ) 16 Assume Zeros Works both ways (Binary to Hex & Hex to Binary)
Octal − Hexadecimal Conversion Hexadecimal DecimalOctal Binary
Octal − Hexadecimal Conversion Convert to Binary as an intermediate step Example: ( ) 2 ( ) 16 Assume Zeros Works both ways (Octal to Hex & Hex to Octal) ( ) 8 Assume Zeros
Example = ? E = 23E 16
Hexadecimal to Octal Hexadecimal DecimalOctal Binary
Example 1F0C 16 = ? 8 1 F 0 C F0C 16 =
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal AF Skip answer Answer
Exercise – Convert … DecimalBinaryOctal Hexa- decimal C AF Answer
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal C.82 Skip answer Answer
Exercise – Convert … DecimalBinaryOctal Hexa- decimal …35.63…1D.CC… D C C.82 Answer
Common Powers (1 of 2) Base 10 PowerPrefaceSymbol picop nanon micro millim 10 3 kilok 10 6 megaM 10 9 gigaG teraT Value
Common Powers (2 of 2) n2n2n 02 0 = = = = = = = =128 n2n2n 82 8 = = = = = =1M =1G =1T Mega Giga Tera Kilo Base 2
Example / 2 30 = In the lab… 1. Double click on My Computer 2. Right click on C: 3. Click on Properties
Exercise – Free Space Determine the “free space” on all drives on a machine in the lab Drive Free space BytesGB A: C: D: E: etc.
BINARY MATH
Review – multiplying powers For common bases, add powers 2 6 2 10 = 2 16 = 65,536 or… 2 6 2 10 = 64 2 10 = 64k a b a c = a b+c
Decimal Addition Example ) Add = 15 Write down 5, carry ) Add = 8 Write down 8 3) Add = 14 Write down 4, carry 1 2) Add = 11 Write down 1, carry 1 Add 3758 to 4657:
Decimal Addition Explanation What just happened? (carry) (sum) (subtract the base) So when the sum of a column is equal to or greater than the base, we subtract the base from the sum, record the difference, and carry one to the next column to the left.
Addition Decimal Addition = Ten ≥ Base Subtract a Base 11Carry
Binary Addition 4 Possible Binary Addition Combinations: (1) 0(2) (3) 1(4) SumCarry Note that leading zeroes are frequently dropped.
Binary Addition Rules Rules: = 0 = 1 = 1(just like in decimal) 1 + 1= 2 10 = 10 2 = 0 with 1 to carry = 3 10 = 11 2 = 1 with 1 to carry
Binary Addition Column Addition ≥ (2) = 61 = 23 = 84
Binary Addition Example Example 1: Add binary to Col 1) Add = 1 Write 1 Col 2) Add = 1 Write 1 Col 3) Add = 2 (10 in binary) Write 0, carry 1 Col 4) Add = 2 Write 0, carry 1 Col 6) Add = 2 Write 0, carry 1 Col 5) Add = 3 (11 in binary) Write 1, carry 1 Col 7) Bring down the carried 1 Write 1
Binary Addition Explanation In the first two columns, there were no carries. In column 3, we add = 2 Since 2 is equal to the base, subtract the base from the sum and carry 1. In column 4, we also subtract the base from the sum and carry 1. In column 6, we also subtract the base from the sum and carry 1. In column 5, we also subtract the base from the sum and carry 1. In column 7, we just bring down the carried What is actually happened when we carried in binary?
Binary Addition Verification Verification = = You can always check your answer by converting the figures to decimal, doing the addition, and comparing the answers.
Binary Addition Example 2 Verification = = Example 2: Add 1111 to
Binary Addition Two 1-bit values ABA + B “two”
Decimal Subtraction Example Subtract 4657 from 8025: )Try to subtract 5 – 7 can’t. Must borrow 10 from next column. 4) Subtract 7 – 4 = 3 3) Subtract 9 – 6 = 3 2)Try to subtract 1 – 5 can’t. Must borrow 10 from next column. But next column is 0, so must go to column after next to borrow. Add the borrowed 10 to the original 0. Now you can borrow 10 from this column. Add the borrowed 10 to the original 5. Then subtract 15 – 7 = 8. Add the borrowed 10 to the original 1.. Then subract 11 – 5 = 6
Decimal Subtraction Explanation So when you cannot subtract, you borrow from the column to the left. The amount borrowed is 1 base unit, which in decimal is 10. The 10 is added to the original column value, so you will be able to subtract
Binary Subtraction Explanation In binary, the base unit is 2 So when you cannot subtract, you borrow from the column to the left. The amount borrowed is 2. The 2 is added to the original column value, so you will be able to subtract.
Binary Subtraction Two 1-bit values ABA - B with borrow 10
Binary Subtraction Example Example 1: Subtract binary from Col 1) Subtract 1 – 0 = 1 Col 5) Try to subtract 0 – 1 can’t. Must borrow from next column. Col 4) Subtract 1 – 1 = 0 Col 3) Try to subtract 0 – 1 can’t. Must borrow 2 from next column. But next column is 0, so must go to column after next to borrow. Add the borrowed 2 to the 0 on the right. Now you can borrow from this column (leaving 1 remaining). Col 2) Subtract 1 – 0 = 1 Add the borrowed 2 to the original 0. Then subtract 2 – 1 = 1 1 Add the borrowed 2 to the remaining 0. Then subtract 2 – 1 = 1 Col 6) Remaining leading 0 can be ignored.
Binary Subtraction Verification Verification = = Subtract binary from :
Binary Subtraction Example Example 2: Subtract binary from Verification = = 21 10
Binary Subtraction Borrow a “Base” when needed − = (10) = 77 = 23 = 54
Multiplication (1 of 3) Decimal (just for fun) 35 x
Multiplication (2 of 3) Binary, two 1-bit values AB A B
Multiplication (3 of 3) Binary, two n-bit values As with decimal values E.g., 1110 x
Binary Multiplication Bit by bit x
Complements & Signed Numbers 87
1.5Complements There are two types of complements for each base-r system: the radix complement and diminished radix complement. Diminished Radix Complement - (r-1)’s Complement Given a number N in base r having n digits, the (r–1)’s complement of N is defined as: (r n –1) – N Example for 6-digit decimal numbers: 9’s complement is (r n – 1)–N = (10 6 –1)–N = –N 9’s complement of is – = Example for 7-digit binary numbers: 1’s complement is (r n – 1) – N = (2 7 –1)–N = –N 1’s complement of is – = Observation: Subtraction from (r n – 1) will never require a borrow Diminished radix complement can be computed digit-by-digit For binary: 1 – 0 = 1 and 1 – 1 = 0
Complements 11’s Complement (Diminished Radix Complement) AAll ‘0’s become ‘1’s AAll ‘1’s become ‘0’s Example ( ) 2 ( ) 2 If you add a number and its 1’s complement …
Complements Radix Complement Example: Base-10 Example: Base-2 The r's complement of an n-digit number N in base r is defined as r n – N for N ≠ 0 and as 0 for N = 0. Comparing with the (r 1) 's complement, we note that the r's complement is obtained by adding 1 to the (r 1) 's complement, since r n – N = [(r n 1) – N] + 1. The 10's complement of is The 10's complement of is The 2's complement of is The 2's complement of is
Complements 22’s Complement (Radix Complement) TTake 1’s complement then add 1 TToggle all bits to the left of the first ‘1’ from the right Example: Number: 1’s Comp.: OR
Complements Subtraction with Complements The subtraction of two n-digit unsigned numbers M – N in base r can be done as follows:
Complements Example 1.5 Using 10's complement, subtract – Example 1.6 Using 10's complement, subtract 3250 – There is no end carry. Therefore, the answer is – (10's complement of 30718) =
Complements Example 1.7 Given the two binary numbers X = and Y = , perform the subtraction (a) X – Y ; and (b) Y X, by using 2's complement. There is no end carry. Therefore, the answer is Y – X = (2's complement of ) =
1.6Signed Binary Numbers To represent negative integers, we need a notation for negative values. It is customary to represent the sign with a bit placed in the leftmost position of the number since binary digits. The convention is to make the sign bit 0 for positive and 1 for negative. Example:
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed 1’s Complement The 1’s complement of a binary number is just the inverse of the digits. To form the 1’s complement, change all 0’s to 1’s and all 1’s to 0’s. For example, the 1’s complement of is In digital circuits, the 1’s complement is formed by using inverters:
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed 2’s Complement The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement. Recall that the 1’s complement of is (1’s complement) To form the 2’s complement, add 1: (2’s complement)
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Signed Binary Numbers There are several ways to represent signed binary numbers. In all cases, the MSB in a signed number is the sign bit, that tells you if the number is positive or negative. Computers use a modified 2’s complement for signed numbers. Positive numbers are stored in true form (with a 0 for the sign bit) and negative numbers are stored in complement form (with a 1 for the sign bit). For example, the positive number 58 is written using 8-bits as (true form). Sign bitMagnitude bits
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Signed Binary Numbers Assuming that the sign bit = 128, show that = 58 as a 2’s complement signed number: Column weights: = 58 Negative numbers are written as the 2’s complement of the corresponding positive number. 58 = (complement form) Sign bitMagnitude bits An easy way to read a signed number that uses this notation is to assign the sign bit a column weight of 128 (for an 8-bit number). Then add the column weights for the 1’s. The negative number 58 is written as:
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Floating Point Numbers Express the speed of light, c, in single precision floating point notation. (c = x 10 9 ) Floating point notation is capable of representing very large or small numbers by using a form of scientific notation. A 32-bit single precision number is illustrated. S E (8 bits) F (23 bits) Sign bitMagnitude with MSB droppedBiased exponent (+127) In scientific notation, c = x In binary, c = S = 0 because the number is positive. E = = = F is the next 23 bits after the first 1 is dropped. In floating point notation, c =
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Arithmetic Operations with Signed Numbers Using the signed number notation with negative numbers in 2’s complement form simplifies addition and subtraction of signed numbers. Rules for addition: Add the two signed numbers. Discard any final carries. The result is in signed form. Examples: = = = = = = = = = 9 1 Discard carry
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Arithmetic Operations with Signed Numbers = = = = = +2 Note that if the number of bits required for the answer is exceeded, overflow will occur. This occurs only if both numbers have the same sign. The overflow will be indicated by an incorrect sign bit. Two examples are: Wrong! The answer is incorrect and the sign bit has changed. Discard carry
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Arithmetic Operations with Signed Numbers Rules for subtraction: 2’s complement the subtrahend and add the numbers. Discard any final carries. The result is in signed form = +151 Discard carry 2’s complement subtrahend and add: = = 15 Repeat the examples done previously, but subtract: = = = = +71 Discard carry = = 8 (+30) –(+15) (+14) –( 17) ( 1) –( 8)
104