Here you can find the source of addressToLong(InetAddress address)
Parameter | Description |
---|---|
address | an address whose integer equivalent is desired |
@SuppressWarnings("WeakerAccess") public static long addressToLong(InetAddress address)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; public class Main { /**/* w w w .j ava 2s. co m*/ * Converts the bytes that make up an internet address into the corresponding integer value to make * it easier to perform bit-masking operations on them. * * @param address an address whose integer equivalent is desired * * @return the integer corresponding to that address */ @SuppressWarnings("WeakerAccess") public static long addressToLong(InetAddress address) { long result = 0; for (byte element : address.getAddress()) { result = (result << 8) + unsign(element); } return result; } /** * 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; } }