janvanbesien / java-ipv6

Java library to represent IPv6 addresses, networks, and related concepts
Apache License 2.0
85 stars 33 forks source link

Typos in IPv6AddressHelpers.java #24

Closed xwdeng closed 7 years ago

xwdeng commented 7 years ago

I saw that in mergeLongArrayIntoIPv6Address(long[] longs):

for (int i = 0; i < longs.length; i++)
        {
            if (inHighRange(i))
                high |= (longs[i] << ((longs.length - i - 1) * 16));
            else
                low |= (longs[i] << ((longs.length - i - 1) * 16));
        }

is it a typo since I am thinking it should be:

high |= (longs[i] << ((4 - i - 1) * 16));
janvanbesien commented 7 years ago

I think the result is the same in both cases, thanks to the fact that left shifts on longs only take the six lowest-order bits of the right-hand operand [1]. However your version certainly is the correct thing to do indeed.

[1] http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19

janvanbesien commented 7 years ago

Fixed.