| Dan Mahoney ( @ 2009-06-29 04:30:00 |
So, because I was curious, I decided to calculate, by hand, prime.gushi.org's ip address in decimal. It took me about 10 minutes to do. It took me well over an hour to HTML this entry and draw up and rearrange all the tables, by hand. Maybe you can learn something from it.
prime.gushi.org is: 72.9.101.130.
First step is to reduce each of those to its binary equivalent, as four eight-bit numbers. 8 bits only go up to 255, which might explain to some of you why you could never get more than 255 gems in the original legend of Zelda...
| Bit | 72 | 9 | 101 | 130 |
| 128 | X | |||
| 64 | X | X | ||
| 32 | X | |||
| 16 | ||||
| 8 | X | X | ||
| 4 | X | |||
| 2 | X | |||
| 1 | X | X |
That gives us:
01001000 00001001 01100101 10000010 (the colors will become clear in a moment)
Now, for the above, instead of the above table being 8-bits, we translate to their 32 bit values (note that just like in decimal, the numbers on the right are the "low", or "least significant" numbers!
Just like in decimal where you have the "ones place" or the "tens place", in binary you have the "one place (20)" or the "two place (21)", or the "four place (22)" all the way up to the "two trillion, four hundred seventy four million, four hundred eighty three thousand six hundred fourty eight place (231)", which, zero-inclusive, is 32 bits. Astute readers will notice that each column is double the one before it (this is different from decimal), and also that maxing out all the rightmost columns is one less than the value of the next column, so 1000 (8) is one more than 111 (7) in binary: 111 is the max value with three places, just as 1000 is one more than 999 in decimal; 999 is also the max value with 3 places.
It's the same as our number system, once you run out of spaces, you move up one, but each "place" can only count to "one", and just like a "2" in the "hundreds" place means "200" in decimal, a "1" in the "eight" place in binary means "8"
Admittedly, I used a calculator to get all the powers of 2 below:
| Bit | Power of 2 | Value | Bit | Power of 2 | Value | Bit | Power of 2 | Value | Bit | Power of 2 | Value |
| 31 | 2147483648 | 23 | 8388608 | 15 | 32768 | X | 7 | 128 | |||
| X | 30 | 1073741824 | 22 | 4194304 | X | 14 | 16384 | 6 | 64 | ||
| 29 | 536970912 | 21 | 2097152 | X | 13 | 8192 | 5 | 32 | |||
| 28 | 268435456 | 20 | 1048576 | 12 | 4096 | 4 | 16 | ||||
| X | 27 | 134217728 | X | 19 | 524288 | 11 | 2048 | 3 | 8 | ||
| 26 | 67108864 | 18 | 262144 | X | 10 | 1024 | 2 | 4 | |||
| 25 | 33554432 | 17 | 131072 | 9 | 512 | X | 1 | 2 | |||
| 24 | 16777216 | X | 16 | 65536 | X | 8 | 256 | 0 | 1 |
So, we substitute in as above, and then we add up all the numbers with an X above.
In other words, this IP address is the same as saying:
230 + 227 + 219 + 216 + 214 + 213 + 210 + 28 + 27 + 21 OR:
(commas added for readability only)
1,073,741,824 + 134,217,728 + 524,288 + 65,536 + 16,384 + 8,192 + 1,024 + 256 + 128 + 2 OR:
1208575362. Yeah, that's the "real" address there.
We try to open that in a browser (and yes, browsers recognize decimal IP addresses), and...http://1208575362/there you go. The funny thing is, all the above seems complicated, but computers do it in a split second. After all, when you type something in a browser, your computer doesn't connect to a name, or even a dotted-quad IP address, it makes a connection right to the integer...all the dotted quads are just for us foolish humans.
Let's think of another one. I will guess the IP address of your computer, and post it here in binary for the world to see: 01111111 00000000 00000000 00000001
There you go, decode it, to either its dotted-quad (use the top table) or binary (use the bottom one) equivalent!
So, anyone want to try it with ipv6 addresses? They have 128 bits as opposed to the mundane 32 here, and translating them means learning to count up to F!