Java Hex Convert To fromHex(final String s)

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

Description

from Hex

License

Open Source License

Declaration

public static byte[] fromHex(final String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] fromHex(final char[] hex) {
        final int length = hex.length / 2;
        final byte[] raw = new byte[length];
        for (int i = 0; i < length; i++) {
            final int high = Character.digit(hex[i * 2], 16);
            final int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127) {
                value -= 256;/*from   www. j a va2  s  .  com*/
            }
            raw[i] = (byte) value;
        }
        return raw;
    }

    public static byte[] fromHex(final String s) {
        return fromHex(s.replace(" ", "").toCharArray());
    }
}

Related

  1. fromHex(CharSequence cs)
  2. fromHex(final CharSequence s)
  3. fromHex(final String hex)
  4. fromHex(final String hex)
  5. fromHex(final String hexValue)
  6. fromHex(final String string, final int offset, final int count)
  7. fromHex(String bytesString)
  8. fromHex(String encoded)
  9. fromHex(String hex)