Java Hex Convert To fromHex(String[] data)

Here you can find the source of fromHex(String[] data)

Description

from Hex

License

Open Source License

Declaration

public static byte[] fromHex(String[] data) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] fromHex(String[] data) {
        StringBuilder sb = new StringBuilder();
        for (String s : data) {
            sb.append(s);/*from w  w w. ja va  2  s.  com*/
        }
        return fromHex(sb.toString());
    }

    /**
     * This method is compatible with the output from {@link #toHex(byte)}.
     * 
     * @param data Hexadecimal data
     * @return Binary data
     * @see #toHex(byte[], int)
     */
    public static byte[] fromHex(String data) {
        data = data.replace(" ", "");
        if (data.length() % 2 != 0) {
            throw new RuntimeException("Bad hex string: " + data);
        }
        byte[] bin = new byte[data.length() / 2];
        for (int i = 0; i < bin.length; i++) {
            bin[i] = (byte) (0xff & Integer.parseInt(
                    data.substring(i * 2, i * 2 + 2), 16));
        }
        return bin;
    }
}

Related

  1. fromHex(String src)
  2. fromHex(String str)
  3. fromHex(String str)
  4. fromHex(String string)
  5. fromHex(String text)
  6. fromHex2B(String src)
  7. fromHex8B(String src)
  8. fromHexa(String s)
  9. fromHexBinary(String s)