UNICODE十六進製制陣列轉成中英文

2021-06-04 11:06:27 字數 1323 閱讀 1559

unicode十六進製制的陣列轉成中英文

實現char*轉換成中英文,每兩個char合成乙個wchar_t:

// unicode十六進製制陣列轉成中英文

// hex array to wchar_t*

// wchs == null, wchslen as output(the size of wchs will be used)

// error: return -1

int ycodec::hexarray2wchars(char* hexarry, int hexarrylen, wchar_t* wchs, int* wchslen)

memset(wchs, 0, *wchslen * sizeof(wchar_t));

char tmp[3];

char* phex = hexarry;

wchar_t* pwchs = wchs;

for(int i=0; i= hexarrylen) break;

tmp[1] = *phex++;

// two char to a hex

unsigned short hex = 0x0;

hex = (tmp[0] & 0xff) << 8;

hex |= tmp[1] & 0xff;

// hex to wchar_t

*pwchs++ = (wchar_t)hex;

} return 1;

}

呼叫例項:

//wchar_t* unicode = null;

char ascii = ;

int wchslen = 0;

ycodec ycodec;

// hex array to wchar_t*

if(ycodec.hexarray2wchars(ascii, 32, null, &wchslen) != -1)

delete wchs;

}

在mfc程式中測試通過。

已實現把0x62, 0x4b, 0x67, 0x3a, 0x53, 0xf7, 0x4e, 0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x37, 0x00, 0x36, 0x00, 0x35, 0x00, 0x35, 0x00, 0x32, 0x00, 0x31, 0x00, 0x30, 0x76, 0x84這一串unicode的十六進製制字元陣列轉成中英文。

結果為:

手機號為18887655210的

基本測試通過,暫未發現神馬問題。

進製轉換 十六進製制轉八進位制 十六進製制轉十進位制

在十六進製制轉為八進位制的過程中包含了將十六進製制轉化為二進位制以及將二進位制轉化為八進位制!我自己測試是沒什麼問題,但是在藍橋杯官網的測試系統就顯示執行錯誤qwq 不知道為什麼 附 include includeusing namespace std int main if len2 i 3 2 ...

進製轉換 二進位制轉十六進製制 十六進製制轉十進位制

這幾天在做乙個與plc互動的系統,plc會傳過來一些指令,這些指令是二進位制的格式,要轉為4位十進位制的指令來讀,下面是 部分 public class byteschange int beginindex 0 int length 16 string instructions while true...

漢字轉十六進製制 十六進製制轉漢字的函式

十六進製制轉漢字 public static string getchsfromhex string hex catch 獲得 cp936,chinese超集 system.text.encoding chs system.text.encoding.getencoding 936 code pag...