Binary Explained
DOOManiac
Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
![DOOManiac](http://members.cox.net/doomaniac/mynewhead.jpg)
<div class="IPBDescription">For those that wanted to know</div>In the <a href='http://www.unknownworlds.com/forums/index.php?act=ST&f=10&t=37071' target='_blank'>spamarific quiz thread</a> some people were wondering about what binary was, so I thought I'd be nice and answer their questions.
Basically, binary is a number system that only has two possible values per digit: 0 and 1, whereas our regular system (base10) has 10 possible values per digit: 0,1,2,3,4,5,6,7,8,9. The rules of carrying over apply and that's how you get really long binary numbers really quick. Just as when you're in second grade math, its easier to learn binary by starting with small numbers and moving from right to left.
The basic gist of things is that each column, from RIGHT to LEFT, represents 1,2,4,8,16,32,64,... Notice a trend? Also notice how computers and video games go from 16-bit to 32-bit to 64-bit? Ever notice how resolutions are 640x480, 1024x768, etc? Not a coincidence. :P
The thing to remember with binary is you're always always always adding +1.
For a few examples, I'll have the base10 on the left, and the base2 (binary) on the right...
0 = 0000 (easy eh?)
1 = 0001 (still with me?)
2 = 0010 (you add 1+1, but since the digit is full you carry a 1 over, just as if you added 9+1 in base10 you'd carry a 1)
3 = 0011 (you just add 1)
4 = 0100 (now its in the third from right column, whic represents 4)
5 = 0101 (this is where it gets tricky, as you see there's 4 + 1 = 5)
6 = 0110 (more trickery, as you had a 1 carry over some more!)
7 = 0111
8 = 1000
9 = 1001
10 = 1010
11 = 1011
12 = 1100
13 = 1101
14 = 1110
15 = 1111 (ah ha, we're full! what do you do now? just keep going :P)
16 = 0001 0000 (could also be read as 10000)
you'll notice I've broken things into 4 or 8 digit groupings. This is cause its a lot easier to read that way, and also makes it quite simple to convert to Hexadecimal. Its pretty nice when reading Assembly code.. but all can be saved for lession 2, I think I'll just let this stuff sink in first.
Feel free to ask any questions, and other programmer types if I've made a mistake (don't think I have) or if you have another explaination you feel may help, feel free to post away.
Basically, binary is a number system that only has two possible values per digit: 0 and 1, whereas our regular system (base10) has 10 possible values per digit: 0,1,2,3,4,5,6,7,8,9. The rules of carrying over apply and that's how you get really long binary numbers really quick. Just as when you're in second grade math, its easier to learn binary by starting with small numbers and moving from right to left.
The basic gist of things is that each column, from RIGHT to LEFT, represents 1,2,4,8,16,32,64,... Notice a trend? Also notice how computers and video games go from 16-bit to 32-bit to 64-bit? Ever notice how resolutions are 640x480, 1024x768, etc? Not a coincidence. :P
The thing to remember with binary is you're always always always adding +1.
For a few examples, I'll have the base10 on the left, and the base2 (binary) on the right...
0 = 0000 (easy eh?)
1 = 0001 (still with me?)
2 = 0010 (you add 1+1, but since the digit is full you carry a 1 over, just as if you added 9+1 in base10 you'd carry a 1)
3 = 0011 (you just add 1)
4 = 0100 (now its in the third from right column, whic represents 4)
5 = 0101 (this is where it gets tricky, as you see there's 4 + 1 = 5)
6 = 0110 (more trickery, as you had a 1 carry over some more!)
7 = 0111
8 = 1000
9 = 1001
10 = 1010
11 = 1011
12 = 1100
13 = 1101
14 = 1110
15 = 1111 (ah ha, we're full! what do you do now? just keep going :P)
16 = 0001 0000 (could also be read as 10000)
you'll notice I've broken things into 4 or 8 digit groupings. This is cause its a lot easier to read that way, and also makes it quite simple to convert to Hexadecimal. Its pretty nice when reading Assembly code.. but all can be saved for lession 2, I think I'll just let this stuff sink in first.
Feel free to ask any questions, and other programmer types if I've made a mistake (don't think I have) or if you have another explaination you feel may help, feel free to post away.
Comments
yes it does say something....
010010110101101100101001000
000110001001101001011001110
010000001100010011101010111
010001110100011100110010000
001100001011011100110010000
100000010010010010000001100
011011000010110111001101110
011011110111010000100000011
011000110100101100101001011
000010000001111001011011110
111010100100000011011110111
010001101000011001010111001
000100000011000100111001001
101111011101000110100001100
101011100100111001100100000
011000110110000101101110001
001110111010000100000011001
000110010101101110011110010
0100001
*giggle*
And 1024 with both hands <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
For example, I like base 7.
1
2
3
4
5
6
10
11
12
13
14
15
16
20
1-14. <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
I'm not going to insult you... But if you can't get that, you probably never will.
010010110101101100101001000
000110001001101001011001110
010000001100010011101010111
010001110100011100110010000
001100001011011100110010000
100000010010010010000001100
011011000010110111001101110
011011110111010000100000011
011000110100101100101001011
000010000001111001011011110
111010100100000011011110111
010001101000011001010111001
000100000011000100111001001
101111011101000110100001100
101011100100111001100100000
011000110110000101101110001
001110111010000100000011001
000110010101101110011110010
0100001
*giggle* <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
I like big butts and I cannot lie, you other brothers can't deny!
*giggle*
I'm not going to insult you... But if you can't get that, you probably never will. <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
I understand binary, but not that Base thing KFS was talking about.
P.S - In that quiz thread.. The answer to my question was simple,
stop();
ugh.
I would guess from TEH ASSKEY
<a href='http://www.asciitable.com/' target='_blank'>http://www.asciitable.com/</a>
Oo, and I'll explain the concept of different "bases".
Different "base number systems" are just different ways to write numbers given a certain number of different digits. Most of us use base-10 or "decimal", which means we have ten digits (0123456789). The base-2 or "binary" system uses two digits (01). The thing is, you can invent a number system using any "base". All you have to do is change what "place" each digit is.
For example, in decimal, you have the "ones place", "tens place", "hundreds place", et cetera. These are all powers of 10. (10^0, 10^1, 10^2) In the binary system, as my colleague DOOM explained, the places are powers of 2 (2^0=1, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32). See the pattern here?
So if you wanted, say, a base 7 system, you'd have the ones place, sevens place, forty-nines place, et cetera. And you'd only have 7 digits (0123456). So if you wanted to do the number one thousand three hundred thirty seven in base 7, you could set up your little table like this:
343 49 7 1
==========
| | |
and fill it in like so:
343 49 7 1
==========
3 | 6 |2|0
eg "elite" = 343*3 + 49*6 + 7*2.
so 3620(base 7) = "elite"(base 10) = 10100111001(base 2) = 2471(base 8) = 539(base 16).....
Base 8 and base 16, called "octal" and "hexadecimal", get used by assembly programmers sometimes because they convert very readily into binary, being powers of 2; each group of 4 binary digits translates to exactly 1 hex digit. The octal system uses the digits 01234567, whereas the hexadecimal system uses 0123456789ABCDEF. If you've ever seen a BSoD or similar fatal computer error, you might see something along the lines of "access violation 0x01F49DE302". Were you wondering why there are "letters" in that number? Well, memory addresses are generally referred to in hexadecimal, so there you go.
This help any, SBV? <!--emo&:)--><img src='http://www.natural-selection.org/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
anyways, yes KFS is correct. [edit]And samwise too.[/edit]
Hexadecimal (base 16) works the same way too. But since we don't have a symbol for a number greater than 9, we then use A,B,C,D,E, and F.
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
Here's some examples with Base10 on the left, and Hex on the right:
10 = A
16 = 10 (this is when it gets confusing, heh)
22 = 16
26 = 1A
31 = 1F
32 = 20
40 = 28
45 = 2C
Now, how does Hex relate to binary you ask? Well, it just so happens that its very very easy to do hex-> binary and vice versa conversions when you use the 4-digit grouping on the hex that I used up to.
Example: 00111101 (random number i typed out)
Converted to hex, first you split it into the 4 character chunks: 0011 1101
Now, you simply add up the value of each chunk, and that's the hex value for that column. You can't go over 15, so it works.
<!--c1--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
0011 1101
3 D(D is 13 in hex)<!--c2--></td></tr></table><span class='postcolor'><!--ec2-->
so the Hex version of the number is 3D.
it's almost as evil as figuring out subnet masks
anyways, yes KFS is correct. [edit]And samwise too.[/edit]
Hexadecimal (base 16) works the same way too. But since we don't have a symbol for a number greater than 9, we then use A,B,C,D,E, and F.
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
Here's some examples with Base10 on the left, and Hex on the right:
10 = A
16 = 10 (this is when it gets confusing, heh)
22 = 16
26 = 1A
31 = 1F
32 = 20
40 = 28
45 = 2C
Now, how does Hex relate to binary you ask? Well, it just so happens that its very very easy to do hex-> binary and vice versa conversions when you use the 4-digit grouping on the hex that I used up to.
Example: 00111101 (random number i typed out)
Converted to hex, first you split it into the 4 character chunks: 0011 1101
Now, you simply add up the value of each chunk, and that's the hex value for that column. You can't go over 15, so it works.
<!--c1--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
0011 1101
3 D(D is 13 in hex)<!--c2--></td></tr></table><span class='postcolor'><!--ec2-->
so the Hex version of the number is 3D. <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
I dont understand where you get the numbers for the letters from.. :/
I dont understand where you get the numbers for the letters from.. :/ <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
Having A=10, B=11, et cetera is just the convention that was adopted. Remember, if you're trying to use a base-16 number system, you need 16 different digits, because each individual digit has to be able to represent anything from zero to fifteen. But we only have 10 digits in our number system. Ruh-roh! So when people started using hexadecimal, they just used letters to fill in the missing 6 digits. They could have just as easily invented entirely new characters to use as the missing 6. Or even invented an entire new system altogether that didn't use any of our current Arabic numerals (1, 2, 3, etc). But if you're trying to type stuff out, it's easiest to stick to things that everyone can find on a standard keyboard. ;-)
Ignore hexadecimal for now, if the A=ten thing is confusing you - just focus on my base-7 example, and see if you can wrap your head around that. If you understand how that's all working, then you'll understand why hex needs extra digits. :-)
(EDIT)
Wait, were you still confused about how people translate binary numbers into letters to form messages? Click that link I provided with my earlier post.
What did you use for digits?
A Binary Translator for the lazy ones.
You sir, are the winner. You managed to sum it all up in one line better than any of the rest of us :)
Its not that I'm taking numbers and making them letters, its that I'm using a letter to represent a number. The letter 'A' represents 10, because we don't have a single digit numerical character to represent 10. Likewise, B simply represents 11.
In theory, you could have anything represent the numbers, even squigly lines (which really, isn't that what all writing is anyway?). A-F is just the convention used by who knows who started it
A Binary Translator for the lazy ones. <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
Or you could use the Windows calculator in "scientific" mode. (And don't none of you be all like "What's Windows? I R TEH LINUX MASTAH!!!" because there ain't no HL client on Linux that I know of.)
All information stored or handled by computers is done as numbers, in particular as binary. That includes letters. A computer has no concept of a letter, merely a byte of information (that's 8 bits. A bit is a BInary digiT) which it designates as being a "character". That's why you can try to open, say, a .dll file in notepad and get garbage - that's because it's interpreting every byte as a character when it's actually something else.
But there has to be a standard for what letters the numbers represent. The most common standard is the ASCII table. There are 255 ASCII values. Counting zero, that's 256, which is one byte. In other words, the ASCII table is a translation of all of the values from zero to 255 into corresponding characters and control codes ("What's a control code?" Delete, backspace, tab, and various obsolete signal codes). If you're wondering why 256 values are needed when the our alphabet just has 26 values, remember that this includes numbers, punctuation, @#$%^& etc. and also various other letters (like e` and so on), as well as these mysterious controll codes.
Then there's something called Unicode, which is an attempt to provide a standard which allows for non-Latin alphabets. The first 256 values of the Unicode table are the same as ASCII, and past that there are different ranges allocated for different alphabets. Unicode is still less than perfect, and runs into a lot of difficulty when dealing with the various Japanese, Chinese and Korean character sets (some of which aren't actually an alphabet at all but are pictograms) due to the sheer number of symbols.
I actually did use this stuff not that long ago, when I wanted to hardcode a bitmap into a program I was writing as a mouse pointer easter egg (type in L4M8D4 and the pointer turns into a crowbar). I drew the crowbar in Paint, laboriously typed it out as 1s and 0s in my source code, and then realized I had to convert the entire page of bits into hex or decimal. Thanks to that whole 4 binary digits = 1 hex digit thing, though, I was able to do clever things with "Find and Replace" and convert the whole thing over in a few blinks of an eye.
Ph34r. <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif'><!--endemo-->