@Test public void test16bithex2int() { assertEquals(IPUtils.hex16bit2int(""), 0); assertEquals(IPUtils.hex16bit2int("f"), 15); assertEquals(IPUtils.hex16bit2int("fff"), 4095); assertEquals(IPUtils.hex16bit2int("ffff"), 65535); assertEquals(IPUtils.hex16bit2int("12345"), -1); assertEquals(IPUtils.hex16bit2int("0000"), 0); assertEquals(IPUtils.hex16bit2int("FFff"), 65535); assertEquals(IPUtils.hex16bit2int("0100"), 256); assertEquals(IPUtils.hex16bit2int("8000"), 32768); }
public static int hex16bit2int(String in) { int i; int last; int base; int v; byte[] hex; int out; out = 0; base = 1; if (in == null) { return -1; } hex = in.getBytes(); if (hex.length > 4) { return -1; } last = hex.length - 1; for (i = last; i >= 0; i--) { v = nibble2int(hex[i]); if (v == -1) { return -1; } out += v * base; base *= 16; } return out; }
IPUtils { public static int hex16bit2int(String in) { int i; int last; int base; int v; byte[] hex; int out; out = 0; base = 1; if (in == null) { return -1; } hex = in.getBytes(); if (hex.length > 4) { return -1; } last = hex.length - 1; for (i = last; i >= 0; i--) { v = nibble2int(hex[i]); if (v == -1) { return -1; } out += v * base; base *= 16; } return out; } }
IPUtils { public static int hex16bit2int(String in) { int i; int last; int base; int v; byte[] hex; int out; out = 0; base = 1; if (in == null) { return -1; } hex = in.getBytes(); if (hex.length > 4) { return -1; } last = hex.length - 1; for (i = last; i >= 0; i--) { v = nibble2int(hex[i]); if (v == -1) { return -1; } out += v * base; base *= 16; } return out; }  }
IPUtils { public static int hex16bit2int(String in) { int i; int last; int base; int v; byte[] hex; int out; out = 0; base = 1; if (in == null) { return -1; } hex = in.getBytes(); if (hex.length > 4) { return -1; } last = hex.length - 1; for (i = last; i >= 0; i--) { v = nibble2int(hex[i]); if (v == -1) { return -1; } out += v * base; base *= 16; } return out; }  static Integer rndInt(int lo, int hi); static Double rndDouble(double lo, double hi); static Integer rndPosInt(int lo, int hi); static String rndIp(); static Object rndChoice(List oList); static Object rndChoice(Object[] oArray); static String rndperc(); static final int ubyte2int(byte in); static final byte int2ubyte(int in); static boolean isValidIpv6String(String in); static final boolean isValidIpv4Subnet(String in); static boolean isValidIpv6Subnet(String in); static boolean isValidIpv4String(String in); static int nibble2int(byte nibble); static final byte int2nibble(int in); static String int16bit2hex(int i16); static int hex16bit2int(String in); static boolean IP4RegEx(String ip); static boolean IP6RegEx(String ip); static boolean IPRegEx(String ip); }
IPUtils { public static int hex16bit2int(String in) { int i; int last; int base; int v; byte[] hex; int out; out = 0; base = 1; if (in == null) { return -1; } hex = in.getBytes(); if (hex.length > 4) { return -1; } last = hex.length - 1; for (i = last; i >= 0; i--) { v = nibble2int(hex[i]); if (v == -1) { return -1; } out += v * base; base *= 16; } return out; }  static Integer rndInt(int lo, int hi); static Double rndDouble(double lo, double hi); static Integer rndPosInt(int lo, int hi); static String rndIp(); static Object rndChoice(List oList); static Object rndChoice(Object[] oArray); static String rndperc(); static final int ubyte2int(byte in); static final byte int2ubyte(int in); static boolean isValidIpv6String(String in); static final boolean isValidIpv4Subnet(String in); static boolean isValidIpv6Subnet(String in); static boolean isValidIpv4String(String in); static int nibble2int(byte nibble); static final byte int2nibble(int in); static String int16bit2hex(int i16); static int hex16bit2int(String in); static boolean IP4RegEx(String ip); static boolean IP6RegEx(String ip); static boolean IPRegEx(String ip);  }