public static int convert2Int(byte[] hex) {
// Code from Ajp11, from Apache's JServ
// assert b.length==4
// assert valid data
int len;
if(hex.length < 4 ) return 0;
if( DEC[hex[0]]< 0 )
throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
len = DEC[hex[0]];
len = len < < 4;
if( DEC[hex[1]]< 0 )
throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
len += DEC[hex[1]];
len = len < < 4;
if( DEC[hex[2]]< 0 )
throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
len += DEC[hex[2]];
len = len < < 4;
if( DEC[hex[3]]< 0 )
throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
len += DEC[hex[3]];
return len;
}
Convert 4 hex digits to an int, and return the number of converted
bytes. |