Question

I have a binary sequence that is supposed to be an IPv6 and I am not sure if I've converted it correctly, can you please check and tell me if it's wrong?

Here is the binary sequence:

0000000000000000 0001100000000000 0000011000000000 0000000000000000 0000000001100000 0000000000011000 0000000000000110 0000000000000001

and here is what I got:

0:1800:600::60:18:6:1

Thanks!

Update: here is the algorithm that I used to generate the hex values:

IPv6 is consisted of 128 bits, I devide it into 8 different groups of 16 bits, get a group of 16 bits and devide it into 4 groups of 4 bits then I convert every group of 4 bits into hex, join the 4 different values I get, then repeat for the rest (7 groups) of 16 bits(2B). After that I add ':' between every group of (now) hex values. Find and remove the zeros from the front of the groups, then, find the biggest subsequence that are consisted only of zeros, remove them and leave only "::" instead.

Was it helpful?

Solution

If this was an IPv6 address, your decoding would be correct (modulo some endianess issues that would result in reordering of bytes). Unfortunately, every set of 128 bits can be an IPv6 address. As @Sander Steffann noted, the IPv6 address you calculated is not currently valid. RFC 4291 describes the IPv6 Addressing Architecture, and the IANA IPv6 Address Space Assignments show which allowed addresses are reserved for what. For addresses starting with eight zeroes (0000::/8), there are only the following valid ranges: The unspecified address, only consisting of zeroes (::/128); the loopback address (::1/128); IPv4 mapped addresses (::ffff:0:0/96), which are starting with 80 zero bits; and the deprecated "IPv4-compatible IPv6 addresses" (0000::/96), which even start with 96 zero bits.


But the other problem I have with that bit sequence: it looks too regular. Let's see what happens, if we count the ones and zeroes with a bit of Perl:

$ echo "0000000000000000 0001100000000000 0000011000000000 0000000000000000 0000000001100000 0000000000011000 0000000000000110 0000000000000001" | perl -wple 's/ //g; s/(0+|1+)/length($1)."x".substr($1,0,1)." "/ge'
19x0 2x1 16x0 2x1 34x0 2x1 16x0 2x1 16x0 2x1 16x0 1x1

(The code just substitutes every sequence of 1s or 0s with the length, a "x" and the first character of the sequence.)

If we exclude the start and end, we always have a sequence of 16 zeroes, then two ones. (In the middle, we have two zeroes instead of the ones, so a sequence of 34 zeroes in total.)

Maybe you're looking at the wrong part of your bit sequence?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top