Java Convert via ByteBuffer hexToBytes(String hexStr)

Here you can find the source of hexToBytes(String hexStr)

Description

hex To Bytes

License

Apache License

Declaration

public static byte[] hexToBytes(String hexStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    public static byte[] hexToBytes(String hexStr) {
        ByteBuffer bytes = ByteBuffer.allocate(hexStr.length() / 2);
        for (int i = 0; i < hexStr.length(); i += 2) {
            Byte b = (byte) (0xff & Integer.parseInt(hexStr.substring(i, i + 2), 16));
            bytes.put(b);//  w w  w.  j  a  v a2s.  co  m
        }
        return bytes.array();
    }
}

Related

  1. hexDump(byte... b)
  2. hexDump(byte[] buffer)
  3. hexStringToBytes(String hexString)
  4. hexStrToStr(String hexStr)
  5. hexToAscii(byte[] src)
  6. hexToBytes(String hexString)
  7. intArrayFromBytes(byte[] bytes)
  8. intArrayToByteArray(int[] intArray)
  9. intArrayToBytes(Collection values)