Java Hex Convert To fromHex(String s)

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

Description

Converts a hex string representation of bytes into a byte array

License

Open Source License

Parameter

Parameter Description
s hex string

Return

byte array

Declaration

static byte[] fromHex(String s) 

Method Source Code

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

public class Main {
    /**/* w w  w  .j  a va  2s .  c  o  m*/
     * Converts a hex string representation of bytes into a byte array
     * @param s hex string
     * @return byte array
     */
    static byte[] fromHex(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
        }
        return data;
    }
}

Related

  1. fromHex(String hexData)
  2. fromHex(String hexStr)
  3. fromHex(String hexString)
  4. fromHex(String hexString)
  5. fromHex(String input, int max)
  6. fromHex(String s)
  7. fromHex(String s)
  8. fromHex(String s)
  9. fromHex(String s)