My question is How to get the maximum number of hosts that can be used on the network to which the specified IP address belongs.

i have a java method like this, which has two arguments ip address and subnet mask address.
When i google i found the formula but i dont know how to write with java.
The formula is 

> 
> The maximum number of hosts can be determined from the number of hosts
>  available in the network, It is the number obtained by subtracting two
>  of less and broadcast address.
> 
> 
> 

```
public static int maxHostNum(String _ip, String _subnetMask) throws UnknownHostException {
    byte[] bIP = InetAddress.getByName(_ip).getAddress();
    byte[] bSB = InetAddress.getByName(_subnetMask).getAddress();
    byte[] bNT = new byte[4];
    for (int i=0; i<bIP.length; i++) {
        bNT[i] = (byte) (~bSB[i] | bIP[i]);
    }
    String broadcastAddress = InetAddress.getByAddress(bNT).toString();

    // i dont know the rest

    return maxHostNum;
}

```

**I know Apache common library can do this but i just want to do without using library**