In C/C + +, ASCII is supported, but GB2312 is compatible with ASCII in Chinese character coding, so the GB2312 encoding of Chinese characters can be obtained
The GB2312 is two bytes, the first byte is high eight bits, the second byte is low eight bits, such as the following program:
#include <stdio.h>
#include <string.h>
int main ()
{
Char a[5];
strcpy (A, "ah");
printf ("%xh%xh\n", (unsigned char) a[0], (unsigned char) a[1]);
return 0;
}
A[0] is the "ah" character of the high eight-bit, a[1] is low eight bits, the program run result is a[0]=b0 A[1]=A1, with 16 in the system, so "ah" word GB2312 code is B0A1 ~
The output is coerced to unsigned char, otherwise it becomes negative because the encoding is a 8-bit unsigned integer.
Of course, you can turn it into 10, for example.
int b;
b= (unsigned char) a[0]*256+ (unsigned char) a[1];
b that is the 10 binary GB2312 of the Chinese character encoded
% a,% A read in a floating point value (only C99 is valid)
% c reads a character
% d read in decimal integer
% i Read in decimal, octal, hexadecimal integer
% o read octal integer
% x,% X read in hexadecimal integer
% s reads a character string and ends with a space, tab, or newline character.
% f,% F,% e,% E,% g,% G are used to input real numbers, which can be entered in decimal or exponential form.
% p reads in a pointer
% u reads in an unsigned decimal integer
% n The number of equivalent characters of the value read so far
% [] Scanning character set
%% read% symbol
Reprint: http://blog.csdn.net/han_kin/article/details/47838715
Raspberry Pi Route (032)-Character issues (2)-How to get a GB2312 encoding of a Chinese character in C language (RPM)