如果我有如下字符:
wchar_t c = '\x0A'
Run Code Online (Sandbox Code Playgroud)
什么是一种简单的方法来转换它,使它变成如下:
wchar_t dst[] ==> "0A"
Run Code Online (Sandbox Code Playgroud)
基本上,c的十六进制值变为字符串值.
积分值c将是0x0A(10在基数10中).您可以使用sprintf它将其格式化为十六进制:
wchar_t c = '\x0A';
int c_val = c;
char string[3];
sprintf( string, "%.2X", c_val );
Run Code Online (Sandbox Code Playgroud)
请注意,c_val不需要中间变量,仅为了清楚起见而添加
或者你可以手动完成:
int c_low = c & 0x0F;
int c_high = ( c & 0xF0 ) >> 4;
...translate c_low and c_high to its textual representation...
Run Code Online (Sandbox Code Playgroud)