100 likes | 308 Views
Decimal To Binary. Basic Data Types. Remember when we first talked about the different combinations of ‘on’ and ‘off’ positions for a given number of light switches :. With 3-bits, there are 8 possible combinations : 000 100 001 101 010 110 011 111.
E N D
Decimal To Binary Basic Data Types Remember when we first talked about the different combinations of ‘on’ and ‘off’ positions for a given number of light switches: With 3-bits, there are 8 possible combinations: 000 100 001 101 010 110 011 111 And, with 4-bits, there are 16 possible combinations: 0000 0100 1000 1100 0001 0101 1001 1101 0010 0110 1010 1110 0011 0111 1100 1111
The same sequencing pattern is used to represent numeric values Basic Data Types Decimal Binary Decimal Binary Decimal Binary 0 0 10 1010 20 10100 1 1 11 1011 21 10101 2 10 12 1100 22 10110 11 3 13 1101 23 10111 4 100 14 1110 24 11000 5 101 1111 25 11001 15 6 110 16 10000 26 11010 7 111 17 10001 27 11011 8 1000 10010 28 11100 18 9 1001 19 10011 29 11101
95 95 Minutes Total 60 5752 5700 52 52 Seconds 1 1 Hour Total 60 95 60 35 35 Minutes Is there any way of converting from decimal to binary?? Yes - The procedure is similar to one which we use all the time. Basic Data Types Suppose you were asked to convert 5,752 seconds to Hours, Minutes, and Seconds. How would you do it???? Because there are 60 seconds to each minute: Because there are 60 minutes to each hour: So 5,752 Seconds = 1 hour, 35 minutes, and 52 seconds
Number Hours Total Seconds Number Seconds Secs. Per Minute Total Minutes Number Minutes Check: Basic Data Types 1 Hour * 60 = 60 Minutes 35 Minutes 95 Minutes * 60 Seconds 5,700 Seconds + 52 Seconds 5,752 Seconds Example #2: Convert 575 Inches to Yards, Feet, and Inches.
47 Total Feet 12 575 564 11 No. Inches 15 No. Yards 3 47 45 2 No. Feet Because there 12 Inches in a Foot: Basic Data Types Because there 3 Feet in a Yard: And so there are 15 yards, 2 feet, and 11 inches in 575 inches. Check: 3 * 15 = 45 + 2 47 * 12 = 564 + 11 = 575 Inches
What does this have to do with converting from decimal to binary?? Basic Data Types Instead of dividing by 60 • for hours to minutes or minutes to seconds • OR by 12 • for inches to feet • OR by 3 • for feet to yards • We divide by 2 • for decimal to binary • AND keep track of the remainders. Reconstructing the number from LAST to FIRST
5 2 11 10 1 2 2 5 4 1 1 2 2 2 0 0 2 1 0 1 Take, for example, the number 1110 (which we know is 10112) • FIRST, Divide 11 by 2: Basic Data Types • NEXT, Let the quotient become the new Dividend • CONTINUE Until the Quotient is Zero (0) • FINALLY, Collect the remainders from Last to First 1 0 1 12 = 11 (Check the Table)
2 28 2 1 2 3 2 7 2 14 Example 2: Convert 2810 to binary (= 111002): (The notation used varies slightly to save space) Basic Data Types Quotient Remainder (If Even = 0; If Odd = 1) 0 Collecting Remainders from last to first: 0 The Binary Value is: 1 1 1 1 0 02 1 1 The New Quotient is Zero: Quit
Example 3: Convert 4410 to binary: The notation used differs to correspond to c syntax: / Integer Division: The result is the quotient % Modulus Arithmetic: The Result is the Remainder Basic Data Types Collecting from Last to First: 44/2 = 22 44 % 2 = 0 22/2 = 11 22 % 2 = 0 1 0 1 1 0 02 11/2 = 5 11 % 2 = 1 5/2 = 2 5 % 2 = 1 2/2 = 1 2 % 2 = 0 1/2 = 0 1 % 2 = 1 Since the New Quotient is 0: STOP
This Concludes The Slides for this Section Choose an Option: Repeat Slides for this Section Go To Next Set of Slides For this Chapter Go To Slide Index For Chapter 2 Go To Slide Index For Chapter 3 Go To Slide Index For Textbook Go To Home Page