Reference: http://www.94cto.com/index/Article/content/id/4.html
It is assumed to be stored as an integer eight bit bits.
1. Symbol:& | ^ ~ << >>
2. Logical rules and arithmetic rules:& | ^ ~ All 8-bit all changed.
Note: bit operations apply to integers, and integers are stored in complementary form in memory. Includes sign bit and value bit, sign bit 0 positive 1 negative.
3. << >> to take into account the sign bit, positive numbers are the same (right shift left 0), negative words, look at the compiler to go, right shift: Left 0 complement 1 see compiler, GCC is the complement 1.
---------------------------
Example: In logic: 0 false 1 True
1. &
Two is true, otherwise it is false
2. |
One is true, otherwise it is false
3. ^
Two bits values are equal to 0, otherwise 1
#include <stdio.h>
Main ()
{
int a=071;
int b = 052;
printf ("%o\n", a^b); 23
}
00111001
^00101010
----------
00010011
4. ~
All bits are reversed
5. << >>
Take the right shift for example:
Positive number: Left 0
Negative number: Left 1
#include <stdio.h>
main ()
{
/*
a=-7
y:10000111
f:11111000
b:11111001//~a:00000110 6
b:11111100
f:11111011
y : 10000100
*/
Span style= "FONT-SIZE:18PX;" > int a=-7;
printf ("%d \n%d\n", ~a,a>>1);//6-4
C-Language bitwise operators