从十六进制值转换为String

问题描述

| 在我的程序中,我得到了六进制格式的字符串。我想将其转换为字符串。怎么做 ? 谢谢并恭祝安康。 帕尔瓦蒂     

解决方法

        使用以下代码将十六进制转换为字符串
String hexadecimalnumber = \"00000011\";
    BigInteger big = new BigInteger(hexadecimalnumber);
    String requiredString = big.toString(16);
    System.out.println(\"...data...\"+requiredString);
谢谢 迪帕克     ,        
String hex = \"ff\";
hex = Integer.toString(Integer.parseInt(hex,16));
    ,        
class Test 
{
    private static int hextoint(char c) {
        if (c >= \'0\' && c <= \'9\') {
            return c - \'0\';
        }
        if (c >= \'a\' && c <= \'f\') {
            return c - \'a\' + 10;
        }
        if (c >= \'A\' && c <= \'F\') {
            return c - \'A\' + 10;
        }
        return -1;
    }

    private static String hexdec(String str) {
        int len = str.length();
        if(len % 2 != 0){
            return null;
        }
        byte[] buf = new byte[len/2];
        int size = 0;
        for (int i = 0; i < len; i += 2) {
            char c1 = str.charAt(i);
            char c2 = str.charAt(i + 1);
            int b = (hextoint(c1) << 4) + hextoint(c2);
            buf[size++] = (byte)b;
        }

        return new String(buf,size);
    }

    public static void main(String[] args) 
    {
        String str = \"616263\";
        String out = hexdec(str);
        System.out.println(out);
    }
}