public IPv6Address add ( int value ) { final long newLowBits = lowBits + value ; if ( value >= 0 ) { if ( IPv6AddressHelpers . isLessThanUnsigned ( newLowBits , lowBits ) ) { // oops, we added something positive and the result is smaller -> overflow detected (carry over one bit from low to high) return new IPv6Address ( highBits + 1 , newLowBits ) ; } else { // no overflow return new IPv6Address ( highBits , newLowBits ) ; } } else { if ( IPv6AddressHelpers . isLessThanUnsigned ( lowBits , newLowBits ) ) { // oops, we added something negative and the result is bigger -> overflow detected (carry over one bit from high to low) return new IPv6Address ( highBits - 1 , newLowBits ) ; } else { // no overflow return new IPv6Address ( highBits , newLowBits ) ; } } }
Addition . Will never overflow but wraps around when the highest ip address has been reached .