IPv6 to IPv4 converting by hand questions

MooCow

[H]F Junkie
Joined
Apr 13, 2000
Messages
8,249
So to my understanding, in hex, A= 10, B = 11, and so on. In order to convert hex to decimal, all you'd have to do is rewrite the digits. However, when it came to converting hex to an IP address, I found out from this example that I had to multiply the first digit by 16, then add that result to the second digit, which was not multiplied by 16. Why is this? Multiply Dx16 + 1 to get 209.




IPv6 to IPv4 conversion
  1. Lets start with an IPv6 address that can be converted to IPv4:IPv6 address: ::D190:4E71 - the double colon is zero compression
  2. Since the IPv6 is in a hexadecimal format we will start with the first number, which is D1 and convert that into decimal. In hexadecimal D=13 and 1=1, so we have:D1 - 13 units of 16 and 1 unit of 1 = 209
  3. The second number is: 90. Therefore we have:90 – 9 units of 16 and 0 units of 1 = 144
  4. Next number is: 4E.4E – 4 units of 16 and 14 units of 1 = 78
  5. And the last number: 71.71 – 7 units of 16 and 1 unit of 1 = 113
  6. IPv4 address after conversion is: 209.144.78.113
 
Remember your base numbering systems. IPv6 is base 16, IPv4 is base 10, Binary is base 2. Binary is the part you're forgetting.

Fire up calc, in scientific mode. Enter something in decimal, then click the radio button to change to other bases.

Base 16: 0xD1 = D1
Base 10: 0xD1 = 209
Base 2: 0xD1 = 1101 0001

Now examine the binary. Remember the binary places, starting from right to left, 1s 2s 4s 8s 16s 32s 64s 128s. A one in each place signifies that value, the actually value being the total of each place. So looking in this example you have 1x128 + 1x64 + 0x32 + 1x16 + 0x8 + 0x4 + 0x2 + 1x1. 128+64+16+1 = 209.

Notice the binary, I split into 2 sets of 4 digits. The first set, if converted to decimal is 13, which comes to D in hex. Second set, is 1 in hex. There's your answer.

In the first set, 1 in binary = 16 in decimal, because of it's actual place in the whole byte. Multiplying that set by 16 is just a shortcut.
 
SpaceHonkey is right, but to add to that:

For IPv4, each octet represents eight binary numbers (0's and 1's), three standard numbers (0-255), or two hexadecimal characters (I say characters because hex is letters and numbers). Split the eight binary digits in half, each half representing a hex value. So if you reverse that, two hex characters become eight binary values (four for each characterI've found converting from Base10 to Hex is easier if I convert to binary first, but that's just me.

Shortcuts work, but it's actually not that difficult, and once you learn the numbers you won't need the shortcuts.
 
Yes I am aware of binary positions (128|64|32... etc...)
However I was not aware of such shortcuts. That may be helpful in the future. Also I forgot to convert to binary first and then write out the number in decimal form from there on. I was rusty. Thanks for the help.
 
Back
Top