Java Hex Convert To fromHex8B(String src)

Here you can find the source of fromHex8B(String src)

Description

from Hex B

License

Open Source License

Declaration

public static long fromHex8B(String src) 

Method Source Code

//package com.java2s;

public class Main {
    public static long fromHex8B(String src) {
        byte[] b = fromHex(src);
        int position = 0;
        long l = (b[position++] & 0xff);
        l |= (long) (b[position++] & 0xff) << 8;
        l |= (long) (b[position++] & 0xff) << 16;
        l |= (long) (b[position++] & 0xff) << 24;
        l |= (long) (b[position++] & 0xff) << 32;
        l |= (long) (b[position++] & 0xff) << 40;
        l |= (long) (b[position++] & 0xff) << 48;
        l |= (long) (b[position++] & 0xff) << 56;
        return l;
    }// w  w  w .j a v a  2s .  c  o  m

    public static byte[] fromHex(String src) {
        String[] hex = src.split(" ");
        byte[] b = new byte[hex.length];
        for (int i = 0; i < hex.length; i++) {
            b[i] = (byte) (Integer.parseInt(hex[i], 16) & 0xff);
        }
        return b;
    }

    public static String fromHex(String hexString, String charset) {
        try {
            byte[] b = fromHex(hexString);
            if (charset == null) {
                return new String(b);
            }
            return new String(b, charset);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. fromHex(String str)
  2. fromHex(String string)
  3. fromHex(String text)
  4. fromHex(String[] data)
  5. fromHex2B(String src)
  6. fromHexa(String s)
  7. fromHexBinary(String s)
  8. fromHexChar(char ch)
  9. fromHexChars(char[] chars, int i)