Make You More Indispensable (More Abstract)#
1. Full Adder Replaces Addition#
int add(int a, int b){
if(!a) return b;
return add((a & b) << 1, a ^ b);
}
2. Use More Approximation Symbols#
int i = 100;
do{
//something
}while(i --> 0);
3. Change Array Operations (One-dimensional)#
int a[5] = {1, 2, 3, 4, 5};
for(int i = 0;i < 5;i++){
printf("%d\n", i[a]);
printf("%d\n", (i - 1)[a + 1]);
}
4. Odd or Even Judgment#
int num = 11;
printf("%d\n", num % 2 == 0);
printf("%d\n", num & 1);
5. Use Hexadecimal Values (Representation of -1)#
0xffffffff
6. x * N#
x <<= 1; //x *= 2
x >>= 1; //x /= 2
x = (x << 1) + (x << 3); //x *= 10
7. Swap Variables (a ≠ b)#
int a = 2,b = 3;
a ^= b;
b ^= a;
a ^= b;
//or
a^=b^=a^=b
8. Not Equal [This Method May Have Issues]#
a ≠ b <=> a ^ b
9. int to char#
int a, b;
char ch;
ch = a ^ 48;
b = ch ^ 48;