|
In the Forums... |
Posted: December 10, 2005 Written By: Dan "Tweak Monkey" Kennedy The advice contained in this article is free for use at your own risk. If you can't benefit from this article, please pass it on to someone who can and view our other articles. For technical support, visit the Tweak3D Forums. Lesson 3: Representing Numbers in Binary Using Bits Those 1s and 0s can be used to represent any numbers. Numbers can then be used to represent other objects. How can you represent any number using binary? Using Bits! Bits are just binary digits, or 1s and 0s that can be used to represent larger numbers. The decimal number system is our most common number system and has 10 choices for its digits (0 through 9). A string of decimal numbers uses multiple digits, such as 147 (one hundred forty seven). The understanding of the single digits allows you to understand the string of digits. Binary uses 2 possibilities (0 or 1) to accomplish the same task. The number 2 for example, can be written as 1 0. Since there are only two possible symbols to represent the numbers, two is created by using a second digit. This is done using the power of 2 instead of the power of 10 like decimal. In decimal, 101 represents the following summation: (1 * 10^2) + (0 * 10^1) + (1 * 10^0) = (1 * 100) + (0 * 10) + (1 * 1) = 100 + 0 + 1 = 101 In binary, 101 represents the following: (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = (1 * 4) + (0 * 2) + (1 * 1) = 4 + 2 + 1 = 5 Converting to Binary To convert the number 547 to binary, you need to first determine the most significant digit of its binary string. Look at the powers of 2: 2 ^ 0 = 1Find the highest number that fits into 547 at least once. A quick glance shows it's 2 ^ 9 = 512. The most significant bit in your binary string would be its 10th bit (don't forget to count 0!), valued at 1. 1 x x x x x x x x x 9 8 7 6 5 4 3 2 1 0 (the Xs will be figured later) We need the remainder of 547/512 to continue. Take 547-512 = 35. Now the process continues. The next number that 35 fits into is 2 ^ 5 = 32. So our 6th bit will be 1. All numbers between the bits equal to 1 must be 0s or the value would be incorrect when the sum is computed. So far we have: 1 0 0 0 1 x x x x x 9 8 7 6 5 4 3 2 1 0 Find the remainder of 35/32. Take 35-32 = 3. The next value is 2 ^ 1 = 2. Our 2nd bit is 1. 1 0 0 0 1 0 0 0 1 x 9 8 7 6 5 4 3 2 1 0 For the last step, our remainder 1 (from 3/2 = 1 r1) can only fit in 2 ^ 0 = 1 1 0 0 0 1 0 0 0 1 1 (the completed binary string) Calculators can speed up this process considerably. Try running the Windows calculator (Start, Run, calc [hit enter or OK]). Set the mode to Scientific (from View at the top). Input 547, then click the Bin button. Experiment with some basic math like subtracting 1 or 2, and convert back to decimal frequently. You'll see patterns emerge. Binary digits can represent states of various switches and can combine to represent numbers, letters, words, documents, programs, computer software, computer hardware, and all electronic circuits at the basic level. A 10-bit number like 547 can be represented by 10 switches toggled to the correct On/Off setting. You've probably seen the term byte before. A byte is a chunk of 8 bits. This makes it easier to represent large numbers. If a file is downloaded at 6 kilobytes per second, it is downloaded at 48 kilobits per second, or less than a 56Kbps (kilobit per second) modem's maximum speed. A kilobit is 2^10 bits, or 1024 bits. A kilobyte is 8 times this number, or 1024 bytes. A megabit is 2^20 bits, or 1,048,576 bits. A megabyte is 8 times this number, or 2^20 bytes. Some people think a 56K modem can download at 56 kilobytes per second. It is physically limited to 56/8 = 7 kilobytes per second, though the FCC limits it to 54 kbps. Lesson 4: Representing Anything with Binary You can create any number with binary, even numbers less than 1 (you'll usually use tricks, like representing negatives or fractions with extra bits in the front of the number). There are 26 letters in the alphabet, so they can be assigned numbers. You may have heard the term ASCII, which represents the alphabet and other characters with specific numbers. Take the word cab for example: c a b c = 3 (decimal) = 11 (binary) a = 1 (decimal) = 01 (binary) b = 2 (decimal) = 10 (binary) Using long strings, one could make whole sentences including punctuation. Then documents, music, operating systems, or any data in binary. Ever wonder how a document is stored in a computers memory? Using bits. Thousands of 1s and 0s are chained together to form words, formatting, and just about anything you could imagine. Everything you see right now is being represented in your computer's memory by an electric current. Over a million pixels' colors are represented as 1s and 0s, strategically placed in front of you to represent the image your video card is sending to your monitor. You could flip a single 1 to 0 in your system's memory and crash the whole computer or change something as small as a single pixel by a fraction of a color shade. For example, assume you set the font color to black, which in 24-bit color mode is: 00000000 00000000 00000000 If you change just a single bit: 10000000 00000000 00000000 The color of the font changes considerably Putting it All Together Now you know what a bit is, how a bit works, and how a computer uses electric switches just like a light switch to operate. You're probably still scratching your head thinking, "why did I learn all this?" Binary is the language of electronics. It makes sense for an electric circuit to be either ON or OFF, so this logic and number system will be with us as long we use electricity. It's important to understand because computers and other electrical devices are a bigger part of our lives than ever now. If you understand binary, you understand the fundamentals behind the functionality of your cell phone, music stored on your MP3 player, or the programming in your TV remote control. The most important lesson you can learn is that electric circuits, represented by 1s and 0s, can create ANYTHING you could imagine. Isn't that pretty neat? |
||
|
---|