Java XML Hex hexStringToByteArray(String s)

Here you can find the source of hexStringToByteArray(String s)

Description

Converts a hex string to a byte array.

License

Open Source License

Parameter

Parameter Description
s hex string to convert

Return

byte array of converted string

Declaration

public static byte[] hexStringToByteArray(String s) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**/*  w  w  w .  j av a 2 s.co  m*/
     * Converts a hex string to a byte array. Found at
     * http://stackoverflow.com/questions/140131/convert-a-string-representation
     * -of-a-hex-dump-to-a-byte-array-using-java
     * 
     * @param s
     *            hex string to convert
     * @return byte array of converted string
     */
    public static byte[] hexStringToByteArray(String s) {
        s = s.toUpperCase();
        return DatatypeConverter.parseHexBinary(s);
    }
}

Related

  1. hexFromBinary(byte[] value)
  2. hexIn(String s)
  3. hexOut(byte[] byteArray)
  4. hexOutSpaces(byte[] byteArray)
  5. hexStringToByteArray(String hex)
  6. hexStringToBytes(String text)
  7. hexToBytes(final String s)
  8. hexToString(String str)
  9. printHexBinary(byte[] in)