#include <cstdio>intN;voidX1_and () {if(n&1) printf ("odd \ n"); Elseprintf ("even \ n");}voidX2_or () {printf ("%d\n", n|1);//+1 Odd. printf"%d\n", (n|1)-1);//-1 even. }voidX3_xor () {printf ("%d\n", n^1);//parity conversion, +1 odd, 1 even. printf"%d\n", n^1^1);//similar to the law of negative negative positive. }voidX4_not () {unsigned ShortA=2; A=~a;//Note that it is not the same as the direct output ~a. printf"%d\n", a);//after processing, A is the maximum value of the short type. Unsignedintb=N; printf ("%d\n", ~b);//this way output-b-1, note that the equivalent of any integral type is handled as above. }voidX5_SHL () {printf ("%d\n",1<<N);//equal to 1 times 2 of the N-square, so after the binary number each plus a 0, is equivalent to multiply 2. }voidx6_shr () {printf ("%d\n",n>>1);//equals n divisible by 2 1 times. }intMain () {scanf ("%d",&N); X1_and (); //used to determine the parity of integers. X2_or ();//used for adjacent parity conversions. X3_xor ();//Note that the same is 0, the difference is 1, the function ibid. X4_not (); X5_SHL (); X6_shr (); return 0;}
Number theory-bit operations (C + +)