c语言中的左移和右移运算(Left shift and right shift in C language)
c语言中的左移和右移运算(Left shift and right shift in C language)
"Left shift" and "right shift" in C language (< < > > and < < > >)
---------------------------------------------------------
1, various data formats (integer, int, character type, char, etc.) hold several storage units (different compilers are different)
In TC2.0 and keil: (also the ANSI standard)
Char holds 1 bytes (8 bit binary digits). Unsigned char type variables, the maximum value is 0xff (sixteen hexadecimal), 255 (decimal)
Int holds 2 bytes (16 bit binary digits). Unsigned int type variables, the maximum value is 0xFFFF (sixteen hexadecimal), 65535 (decimal)
Long int holds 4 bytes
Folat holds 4 bytes, and long, float, and double hold 8 bytes, and long double makes up 16 bytes
In VC++:
Char holds 1 bytes, int and float hold 4 bytes, and double occupies 8 bytes
-------------------------------------------------------------------
2. The difference between logical left shift / right shift and left shift / right shift of arithmetic (these two bit operations are only for integer and character type). Not applicable to data in real format
Logical left shift: discards the lowest bit and the 0 complement the msb. (assuming only 1 shifts left) binary number: logical left shift 1, get:Logical right shift: discards the MSB, and 0 makes the lowest bit. (assuming only 1 digits to the right) binary number: logical left shift 1, get:Left shift of arithmetic: the left shift of logic is based on keeping the symbol bit constant. (assuming only 1 shifts left) binary number:Arithmetic right shift: the logical right shift is based on keeping the symbol bit constant. (assuming only 1 digits to the right) binary number:------------------------------------------------------------------
Well, get to the point: discuss it in categories and characters
The following results are debugged by VC++6.0 (1 bytes for char, 4 bytes for int)
One thing to note is tha