如何把16进制编码转换为中文
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何把16进制编码转换为中文相关的知识,希望对你有一定的参考价值。
参考技术A void My_Convert(const char* strIn,char* strOut, int sourceCodepage, int targetCodepage)int len = lstrlen(strIn);
int unicodeLen = MultiByteToWideChar(sourceCodepage, 0, strIn, -1, NULL, 0);
wchar_t* pUnicode;
pUnicode = new wchar_t[unicodeLen + 1];
memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage, 0, strIn, -1, (LPWSTR)pUnicode, unicodeLen);
BYTE * pTargetData = NULL;
int targetLen = WideCharToMultiByte(targetCodepage, 0, (LPWSTR)pUnicode, -1, (char *)pTargetData, 0, NULL, NULL);
pTargetData = new BYTE[targetLen + 1];
memset(pTargetData, 0, targetLen + 1);
WideCharToMultiByte(targetCodepage, 0, (LPWSTR)pUnicode, -1, (char *)pTargetData, targetLen, NULL, NULL);
lstrcpy(strOut, (char*)pTargetData);
delete pUnicode;
delete pTargetData;
char acInput[] = 0xe5,0x80,0xbc,0xe4,0xb8,0x8d,0xe8,0x83,0xbd,0xe4,0xb8,0xba,0xe7,0xa9,0xba,0xe3,0x80,0x82,0x0d,0x0a,0xe5,0x8f,0x82,0xe6,0x95,0xb0,0xe5,0x90,0x8d,0x3a,0x20,0x73, 0x00;
char acOutput[256] = 0;
My_Convert(acInput, acOutput, CP_UTF8, CP_ACP);
printf("decode: %s\r\n", acOutput);
这样就可以。
java 汉字按照指定字符集转换为二进制编码 并把二进制编码转换为对应的汉字 方法
public static void main(String [] args) throws UnsupportedEncodingException { int val = 5; System.out.println(Integer.toBinaryString(7)); System.out.println(Integer.toBinaryString(7>>1)); System.out.println(0b111); System.out.println(0b11); System.out.println(Integer.toBinaryString(520)); System.out.println(0b1000001000); String s = "我爱你"; byte [] nn = String.valueOf(s).getBytes("UTF-8"); System.out.println(0xFF); for (int i=0; i< nn.length; i++) { byte ss = nn[i]; System.out.print(ss); } System.out.println(); for (int i=0; i< nn.length; i++) { byte ss = nn[i]; System.out.print(ss & 0xFF); } System.out.println(); for (int i=0; i< nn.length; i++) { byte ss = nn[i]; System.out.print(Integer.toBinaryString((Integer)(ss & 0xFF))); } System.out.println(); //将二进制字符串转换为UTF-8对应的汉字 String binaryStr = "111001101000100010010001111001111000100010110001111001001011110110100000"; String [] binaryArr = new String [binaryStr.length()/8]; for (int i=0; i<binaryStr.length(); i = i + 8) { binaryArr[i/8] = binaryStr.substring(i, i+8); System.out.println(binaryArr[i/8]); } String s1 = String.valueOf(binaryArr); System.out.println(s1); StringBuilder strBuilder = new StringBuilder(); byte [] mm3 = new byte[binaryArr.length]; for(int i=0; i< binaryArr.length; i++) { String m = binaryArr[i]; int nn4 = Integer.parseInt(m, 2); byte mm = (byte)(nn4); mm3[i] = mm; } System.out.print(new String(mm3, Charset.forName("UTF-8"))); }
111
11
7
3
1000001000
520
255
-26-120-111-25-120-79-28-67-96
230136145231136177228189160
111001101000100010010001111001111000100010110001111001001011110110100000
11100110
10001000
10010001
11100111
10001000
10110001
11100100
10111101
10100000
[Ljava.lang.String;@4d76f3f8
我爱你
以上是关于如何把16进制编码转换为中文的主要内容,如果未能解决你的问题,请参考以下文章