Bit operations are often encountered in driver development, especially in the 0 and 1 positions. You can change the number of bits you specify, and you cannot change the value of other bits. You also need to write your code efficiently. This is a very important skill. There are several symbols in the bitwise operation: | Bitwise OR & Bitwise AND ^ XOR ~ bitwise NON
1#include <stdio.h>2 3 intMain ()4 {5 intA =0x1101;6 intb =0x1011;7 intc =9;8printf"A | b is%x\n", a |b);9printf"A & B is%x\n", A &b);Tenprintf"a ^ b is%4x\n", a ^b); Oneprintf"~c is%d\n",~c); A -}
The result is a | B is 1111 A & B are 1001 a ^ B is ~c is-10
The first three results are no problem, the last answer should be focused on understanding. First of all, 9 is written in hexadecimal 0x00000101 to take the non-word is 0xfffffefe. Because C is signed, the highest one is 1 for negative numbers, and negative numbers are shown in the form of a complement in the computer. So to output the decimal number, we need to get the complement-1 ratio first.
Day 16th: C-Step arithmetic and inline assembly