Send a link

Java



Convert a hex string to a byte[] array

This can be used to build a SnmpString and SnmpIpAddress.
String value = "536f6d652054657874";
byte[] hex = new BigInteger(value, 16).toByteArray();


Converting between byte and int

.
    /*
     * Returns the byte as an int.
     */
    public static int byteToInt(byte b) {
        return b & 0xFF;
    }
    
    /*
     * Returns the low byte of an int.
     */
    public static byte intToByte(int i) {
        return (byte)(i & 0x00FF);
    }
    
    /*
     * Returns the high byte of an int.
     */
    public static byte intHighToByte(int i) {
        return (byte)(i & 0xFF00);
    }