Vous êtes sur la page 1sur 9
‘var017 [ABinary Numbers Tutrial with 1 ard | [een cae 1and0 BY TIM SLAVIN / CONCEPTS / SEPTEMBER 2013 ISSUE Binary numbers, based on 1s and Os, reflect the practical essence of computer hardware: electricity is either on or off. Learn how to write in binary numbers, and the (not so secret) code to transform English language letters into binary numbers and back again, Whenis the letter A not the letter A? Well, computers don't use the letter A. They use the eight character binary number 01000001 to represent A. This binary numbers tutorial describes what binary numbers are and how to calculate them. Computers transport, calculate, and translate binary numbers because computer hardware circuits only have two electrical states, on or off. These two states can be represented as zero (off) or one (on). Allletters of the alphabet, numbers, and symbols are converted to eight character binary numbers as you work with them in software on your computer. How you create and translate binary numbers is a good way to learn how computers process data at the lowest level, in their hardware circuits. Also, | provide a free Excel spreadsheet linked at the bottom of this article to help you visualize and calculate binary numbers. The [Not So] Secret Formula To represent the letter A as 01000001, the computer (and you, to follow along) Aneed several basic tools. One tool is an ASCII conversion chart. Without diving into too much technical det: the ASCII chart maps a unique number between 1 and 255 to all letters of the alphabet capitalized (A-Z) and lower case (a-z), as well as numbers (0-9), spaces, and other special characters. The unique ASCII number that maps to each character, for example, the capital letter A, is used to calculate a unique eight-character binary number, a combination of ones and zeroes like 01000001. hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘vaz0%7 [A Binary Numbers Trial with 1 and It's basically a two-step secret code. The first step is to grab the unique ASCII number for a letter. The second step is to create a unique eight character binary number, a combination of ones and zeroes to represent the ASCII number. And, of course, going from the eight character combination of ones and zeros to the letter or character reverses this process: first turn the binary number into a number between 1 and 255, then use the number to look up the letter in the ASCII chart. How to Create Binary Numbers Binary numbers are eight characters in length where every character is either a 1 or 0. The placement of each 1 indicates the value of that position, which is used to calculate the total value of the binary number. Each position of each of the eight characters represents a fixed number value, as shown below. Binary Number Worksheet ‘Example Bry Nurbr: 01000011 EnierBray] Deut Calculated ___Vave_Vive x oF 0 x 2 0 x 6 ° x] ¢ 0 x[ 4 ° x] 2 0 x[ ° {ASCIIDecimal Number[ 0 Binary Numbers with Values and Positions in a Blank Worksheet If you read these Default Value numbers from bottom to top, can you tell how each number immediately above is calculated? They're doubled. So binary numbers start on the bottom with the first position equal to 1. The second position from the bottom has a value 2, the third position 4, and soon. Ifyou add up all these numbers (1+2+4+8+16+32+64+128), can you guess what number you'll get? 255, the highest number used in the ASCII table. There is a perfect mapping between all possible numbers 1 to 255 in the ASCII table and the calculated values for all possible eight character binary numbers. hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘i80017 ABinary Numbers Teoria with # ard | To calculate the number value of a binary number, add up the value for each position of all the 1 in the eight character number. The number 01000001, for example, is converted to 64 + 1 or 65. The ones in this binary number are in the first and seventh positions, counting from the bottom to top, or reading right to left. The first position has an assigned value of 1 while the seventh position has an assigned value of 64. Let's Convert a Letter to a Binary Number Now that you know the [not so] secret formula to convert letters to unique ASCI| numbers to binary numbers, and how to create binary numbers, let's do the whole process step by step. Let's start with the letter C. First, we need to use an ASCII chart like this one below to look up the unique number assigned to the uppercase letter C. The unique decimal number to use is 67. Decimal Character Decimal Character Decimal Character 32 Space 64 @ 96 33 ! 65 A ”7 a 34 . 66 B 98 b 35 # 67 c 99 c 36 $ 68 D 100 d 7 % 6 E 101 e 38 & 70 F 102 f 39 ‘ 71 G 103 8 40 ( 72 H 104 h a ) 73 1 105 i 42 . 74 J 106 i 43 4 75 K 107 k 44 : 7 L 108 I 45 - 7 M 109 m hipsstww kdscodecs.com/a-binary-rumbers-uoria-with- and! ‘var017 [ABinary Numbers Tutrial with 1 ard | 46 : 78 N 110 n 47 / 79 ° 111 ° 48 ° 80 Pp 112 P 49 1 81 Q 113 q 50 2 82 R 414 r 51 3 83 s 115 s 52 4 84 T 116 t 53 5 85 u 117 u 54 6 86 v 118 v 55 7 87 w 119 w 56 8 88 x 120 x 57 9 89 Y 121 y 58 : 90 Zz 122 z 59 ; 91 123 { 60 < 92 124 I 61 = 93 ] 125 } 62 > 94 * 126 - 63 2 95 127 DEL To convert the number for C, 67, into a binary number: Remember how binary numbers are read bottom to top, first position and Default Value to top position and Default Value, with each of the eight character positions assigned a unique number value? With the chart below, what combination of values would equal 67? hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘var017 [ABinary Numbers Tutrial with 1 ard | Binary Number Worksheet ‘Example Bry Nurbr: 01000011 [Eniorsinayy] — Detaut Cacatatog Digits © or 4 ave 6 2 {ASCIIDecimal Number[ 0 ary Numbers with Values and Positions You're correct if you said the Default Values 1 plus 2 plus 64 would equal 67, the ASCII number for the capital letter C. So let's change the first, second, and seventh position zeroes to ones, counted from right to left. The binary number is for the capital letter Cis: Binary Number Worksheet xangie Bina Nurber 07000011 ErierBray] Det Calcwatea Digits or 4 Vave Valve ° x 0 1 x of “ ° x 2 0 ° x 8 a ° ra 0 ° | A o 1 x 2 2 1 x 4 1 ‘ASCHDesal Nonber| —e7 —| The letter C as a Binary Number Can you decode this binary number? Add up the 1s to get 64+16+4 or 84, Look up the decimal number 84 in the ASCII chart to find the letter represented below: hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘var017 [ABinary Numbers Tutrial with 1 ard | Binary Number Worksheet ‘Example Bry Nurbor: 01000011 EnierBnay] —Detaut Cacalatod Digits © or Vave __ Vaue o [x ° 1 x of o o |x 2 0 1 x 6 6 [xls 0 o |x 2 0 oo|e 5 0 [“sseiiDecinat Number] 4] The letter T as a Binary Number Ifyou converted this binary number to the capital letter T, you're correct. Here is the letter A as a binary number to represent the ASCII decimal number for A, which is 65: Binary Number Worksheet xamgeBinay Number 0:000011 Eniersinay] —Detaut Caiculated Digits Ocort)| __Vaue Value ox 18 o x 6 o |x 2 0 o |x 6 a o |x a 0 o |x 4 o o |x 2 0 x4 1 [AseitDecinal Number] 65] The letter Aas a Binary Number If we combine the binary numbers we've looked at so far, we can spell CAT: 01000011 01000001 01010100 Bonus: Pseudo-Code to Design a Binary Number Converter With an understanding of how letters and numbers are converted to binary numbers, and back, let's look at how we might create a software application to make these conversions on the fly. The application has no real value. But it provides a chance to discuss how a process can be converted to software. hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘var017 [ABinary Numbers Tutrial with 1 ard | Instead of actual code, however, we'll write up a series of statements or pseudo-code. Let's take the word cat to start. What process do we need to convert these letters automatically into binary numbers? Here's one possible set of steps we could code: 1. Break the word into individual letters. 2. For each letter, look up the ASCII number value mapped to the letter. 3. For each ASCII number value, convert to a binary number. 4. For each binary number, save the binary number value. If it is the first binary number, create the initial binary number value; if a binary number value exists, add the new binary number to the end of the value. Imagine if we skipped the last step: what would be the result of these steps? We'd only have the last binary number, for the lower case letter t in cat. It's important we capture each binary number as they are created, Other observations about this pseudo-code process? We need to distinguish between capital letters and lower case letters, don't we? Otherwise, our binary number conversion might translate from binary number to ASCII letters as CAT or cAT or Cat. Our lookup to match letters to the ASCII table might grab the wrong number. Bonus Bonus: A Final Puzzle Can you decode the phrase in this set of binary numbers? Remember, these are eight character blocks of 1s and Os. 01000011 01101111 01100100 01100101 01101001 01110011 01010000 01101111 01100101 01110100 01110010 01111001 Here's a fairly easy way to convert any letter into a binary number. Grab a calculator, find the ASCII decimal value for the letter, from the chart above, then look at the binary number chart for the nearest value to the decimal value. Subtract the nearest number Default Value in the binary chart to get a remainder value. Look for the nearest binary Default Value for the remainder. Repeat until you run out of binary values. If you're clever, you'll also note the sum of the values below any of the eight Default Values equals one less than the value: so below the binary value 4 are the values 2 and 1 which equal 3. Below the hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! 79 ‘yaro17 ABinary Numbers Teil with 1 er60 | binary value of 8 are 4, 2, and 1 which equal 7. This also can help convert letters to binary numbers. If your remainder is 7, for example, then you know to put a 1 at the 4, 2, and 1 positions to create that part of your binary number. To convert binary numbers to letters, just grab a piece of paper and a pen or pencil and add up the binary values of all the 1s. Then look up your total number as an ASCII decimal in the chart above. Here's a hint to help determine if you have solved the binary numbers above correctly: | majored in American poetry in college and love the old tagline used for WordPress publishing software. If you want more binary numbers, check out our article about Bakuro binary number puzzles which work like Sudoku. Learn More BINARY NUMBER WORKSHEET (EXCEL FORMAT) https://www,kidscodecs.com/binary-numbers-converter BINARY NUMBERS WORKSHEET (PDF) https://www.kidscodecs.com/binary-numbers-worksheet BINARY CONVERTER http://www.rapidtables.com/convert/number/binary-converter.htm ATUTORIAL ON BINARY NUMBERS http:/Awww.math.grin.edu/~rebelsky/Courses/152/97F/Readings/student-binary BINARY NUMBERS (WIKIPEDIA) https://en.wikipedia.org/wiki/Binary number ASCII TABLE http://www.asciitable.com/ hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and! ‘var017 [ABinary Numbers Tutrial with 1 ard | Share on Social Media HOSA About the Author im Slavin ‘im is an award-winning writer and technologist who enjoys teaching tech to non- echnical people. He has many years experience with web sites and applications in business, technical, and creative roles. He and his wife have two kids, now eenagers, who are mad about video games. hipsstwwue kidscodecs.com/a-binary-rumbers-uoria-with- and!

Vous aimerez peut-être aussi