I've spent a good amount of time in this Industry. Learned how to write good simple program and trying to learn more to reach to intermediate level. Journey was mix of reward and hardwork. Met people with different dimension, different skill set and lately realized I'm not only the person who wants to excel truly by learning the system more and more.
Anyway in few upcomming series, I'll reveal some good approaches which I've learned so far by introspection. Will look more into the digital system and will see how it similar to our daily concepts.
The following example shows the array reversing using the XOR operator . No need to take any additional variable to reverse the array. int main(int argc, _TCHAR* argv[]) { char str[] = "I AM STUDENT"; int length = strlen(str); for(int i = 0; i < ((length/2)); i++) { str[i] ^= str[length - (1+i)]; str[length - (1+i)] ^= str[i]; str[i] ^= str[length - (1+i)]; } cout << str << endl; return 0; } The above example is one of the uses of XOR but XOR comes in handy when we can do branchless coding methods like butterfly switch etc. Sometimes this is very effective in speeding up the execution. Let's see one of the uses of XOR in branchless coding. I am taking a simple example of Y = | X |. Yes, I am generating abs of a supplied number. So, my function signature/definition in C++ looks like below: int absoluteBranch( int x) { if (x < 0 ) { return ...
Comments