Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The difference between char and uchar.
The difference between char and uchar.
1, char is signed, uchar(unsigned char) is unsigned, and 8-bit unsigned plastic data are all positive numbers.

2. There is a difference when they are used as integers:?

The integer range of char is-128 to 127 (0x80 _ 0x7f), while the integer range of unsigned char is 0 to 255( 0__0xFF). Sometimes, if you want to limit integer values to 255, you can also use unsigned characters.

Extended data:

Introduction to char and uchar functions:

Char is used to define character variables in C or C++, occupying only one byte, and the range of values is-128 ~+127 (-2 7 ~ 2 7-1).

C languages such as int, long, short, etc. When they are not specified signed or unsigned, they are all signed by default, but in the standard, char does not specify signed or unsigned. Compilers can perform signed or unsigned V compilation.

Unsigned char is an unsigned byte type, and the size of char type variables is usually 1 byte (1 byte =8 bits), which belongs to integer type.

Every type of integer has two types: unsigned and signed (float and double are always signed). By default, declared integer variables are signed types (char is a bit special). If you want to declare an unsigned type, you need to add the unsigned before the type.

The difference between unsigned version and signed version is that unsigned version can store twice as much data as signed version. For example, in 16 bit system, int can store data in the range of -32768~32767, while unsigned version can store data in the range of 0~65535.

Similarly, in a 32-bit system, the char type is generally 8 bits, so the range of data that can be stored is-128~ 127, while the unsigned char is 0~255. Data stored in character types are used to represent characters, such as ASC or Unicode.

Baidu encyclopedia -—char

Baidu Encyclopedia -—uchar (unsigned characters)