One, bit operation introduction
1, operator:& | ^ ~ << >>
Use: direct operation of binary, save memory, high efficiency.
Note Only the integer operand (char, short,int, long) arithmetic rule can be used:
1) & Bitwise AND full 1 only 1 otherwise 0: only the corresponding two binary are 1 o'clock, the result bit is 1, otherwise 0 with 6 and 3 This example.
#include <stdio.h>int main (int argc, const char * argv[]) { //define two integer variables, do bitwise AND, bitwise OR, bitwise XOR, left SHIFT, right shift int num1=8 , num2=3; printf ("Bitwise AND%d\n", num1&num2);//The result is: 0 printf ("Bitwise OR%d\n", num1|num2);//Result: printf ("Bitwise XOR or%d\n", num1^ NUM2);//results are: printf ("Left Shift%d\n", num1<<num2);//Result: ("Shift right%d\n", num1>>num2);//Result: 1 return 0;}
iOS Development Learning Record the 9th day of C language learning-----bit arithmetic