Download presentation
Presentation is loading. Please wait.
1
The Binary Number System
Acknowledgment and Disclaimer: This presentation is supported in part by the National Science Foundation under Grants , , , , , and Any opinions, findings, and conclusions or recommendations expressed in these materials are those of the authors and do not necessarily reflect the views of the National Science Foundation. *
2
Important CS Principle
Binary sequences -- sequences of 0s and 1s -- are used to represent all computer data. Numbers Letters and text. Images. Machine language instructions. Sounds and video. Every kind of data you find on a computer.
3
Binary vs. Decimal System
Binary system is similar to the decimal system. Both are positional number systems. 542 is Decimal is a base-10 system. 10 digits, 0 through 9 Place values are powers of 10 1s, 10s, 100s, 1000s, etc. Each place is previous place times 10
4
Binary vs. Decimal System
Binary system is similar to the decimal system. Both are positional number systems. 101 is = 5 Binary is a base-2 system. 2 digits, 0 through 1 Place values are powers of 2 1s, 2s, 4s, 8s, 16s, etc. Each place is previous place times 2
5
Why Do Computers Use Binary?
In an electronic circuit, it’s easy to represent the difference between a switch being “on” or “off” or a voltage being “high” or “low”. It’s hard to represent 10 distinct states: “really high voltage”, “pretty high”, …, “pretty low”, “really low”.
6
Amazing Fact By combining 0s and 1s in various combinations we can represent any and all the data that computers use and process!
7
Converting Binary to Decimal (not hard!)
*
8
Converting Binary to Decimal
Here’s a simple algorithm for converting a binary number into its decimal equivalent. Convert binary to decimal
9
Converting Binary to Decimal
Step 1. Write the binary number with some spaces between its digits. Convert binary to decimal 1. Write the number with spaces between the digits.
10
Converting Binary to Decimal
Step 2. Write the binary place values above the number, going right to left: 1s, 2s, 4s, 8s, etc. Convert binary to decimal 1. Write the number with spaces between the digits. 2. Write the binary place values above the number, going right to left.
11
Converting Binary to Decimal
Step 3. Add up the place values that have a 1 beneath them. Convert binary to decimal 1. Write the number with spaces between the digits. 2. Write the binary place values above the number, going right to left. 3. Add up all the place values that have a 1 underneath them. = 21
12
Converting Binary to Decimal
Step 4. The result, the sum, is the decimal value of the original binary number. Convert binary to decimal 1. Write the number with spaces between the digits. 2. Write the binary place values above the number, going right to left. 3. Add up all the place values that have a 1 underneath them. = 21 4. The result is the decimal value of the binary number 21
13
Converting Decimal to Binary (not hard!)
*
14
Converting Decimal to Binary
Here’s an algorithm for going in the opposite direction, converting a decimal number into binary. Let D be the number we want to convert to binary. Suppose D = 25
15
Converting Decimal to Binary
Step 1: Write down D and the binary place values, 1, 2, 4, 8, 16, and so. And put 0s under each place. Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D =
16
Converting Decimal to Binary
Step 2: Find the largest place value that is less than or equal to D and change its 0 to 1. Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D = 2. Find the largest place value that is less than or equal to D and change its 0 to a 1. D =
17
Converting Decimal to Binary
Step 3. Subtract that place value from D and take the result as the new value of D. Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D = 2. Find the largest place value that is less than or equal to D and change its 0 to a 1. D = 3. Subtract that place value from D and take the result as a new value for D. D =
18
Converting Decimal to Binary
Step 4: Repeat steps 2 and 3 until D is 0. Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D = 2. Find the largest place value that is less than or equal to D and change its 0 to a 1. D = 3. Subtract that place value from D and take the result as a new value for D. D = 4. Repeat steps 2 and 3 with the new value of D until D is 0. D =
19
Converting Decimal to Binary
Step 4 (again): Repeat steps 2 and 3 until D becomes 0. Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D = 2. Find the largest place value that is less than or equal to D and change its 0 to a 1. D = 3. Subtract that place value from D and take the result as a new value for D. D = 4. Repeat steps 2 and 3 with the new value of D until D is 0. D = D =
20
Converting Decimal to Binary
Step 5: Now that D is 0 we stop. The value of 25 in decimal is (we drop the leading 0s). Let D be the number we want to convert to binary. Suppose D = 25 1. Write down D and next to it the binary place values with spaces between them with 0s below each place. D = 2. Find the largest place value that is less than or equal to D and change its 0 to a 1. D = 3. Subtract that place value from D and take the result as a new value for D. D = 4. Repeat steps 2 and 3 with the new value of D until D is 0. D = D = 5. The resulting number is the binary equivalent of the original value of D. 25 in decimal is
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.