package org.deepsymmetry.beatlink;

/**
 * Provides utility functions.
 *
 * @author James Elliott
 */
public class Util {
    /**
     * Converts a signed byte to its unsigned int equivalent in the range 0-255.
     *
     * @param b a byte value to be considered an unsigned integer.
     *
     * @return the unsigned version of the byte.
     */
    public static int unsign(byte b) {
        return b & 0xff;
    }

    /**
     * Prevent instantiation.
     */
    private Util() {
        // Nothing to do.
    }
}

@@ -29,16 +29,46 @@
 tlink;%0A%0A
+import java.net.InetAddress;%0A%0A
 /**%0A * P
@@ -146,16 +146,17 @@
  Util %7B%0A
+%0A
     /**%0A
@@ -409,24 +409,24 @@
 n(byte b) %7B%0A
-
         retu
@@ -445,16 +445,1214 @@
 %0A    %7D%0A%0A
+    /**%0A     * Converts the bytes that make up an internet address into the corresponding integer value to make%0A     * it easier to perform bit-masking operations on them.%0A     *%0A     * @param address an address whose integer equivalent is desired.%0A     *%0A     * @return the integer corresponding to that address.%0A     */%0A    public static long addressToLong(InetAddress address) %7B%0A        long result = 0;%0A        for (byte element : address.getAddress()) %7B%0A            result = (result %3C%3C 8) + unsign(element);%0A        %7D%0A        return result;%0A    %7D%0A%0A    /**%0A     * Checks whether two internet addresses are on the same subnet.%0A     *%0A     * @param prefixLength the number of bits within an address that identify the network.%0A     * @param address1 the first address to be compared.%0A     * @param address2 the second address to be compared.%0A     *%0A     * @return true if both addresses share the same network bits.%0A     */%0A    public static boolean sameNetwork(int prefixLength, InetAddress address1, InetAddress address2) %7B%0A        int prefixMask = 0xffffffff & (-1 %3C%3C (32 - prefixLength));%0A        return (addressToLong(address1) & prefixMask) == (addressToLong(address2) & prefixMask);%0A    %7D%0A%0A
     /**%0A

Add network comparison method.