I challenged myself on codefights. However, whenenver i passed a test, I always find that other use very weird expression to conquer all of the test. Some of that look like " n &=~(1<<(k-1)) " . What the heck is all of these expression and where can I learn that. It is a bit of shame but I do not understand this and often use some very “manual” technique to solve the problem.
All that stuff looks cool for challenge solving, but you are never going to use it in a production setting. I totally agree, and I have no idea what half of those things mean (and neither is practically any other developer looking at your code for the first time). You really shouldn’t use that kind of stuff unless you are in some programming contest, hackathon, etc. Your “manual technique” is the proper way to do it. As to where to learn it… I have absolutely no idea… @PortableStick, @P1xt might have an idea…
is the same as:
n = n & ~(1<<(k-1))
& is the bitwise AND operator
<< is the bitwise left shift operator
~ is the bitwise negation operator
I believe this expression is clearing bit “k” inside the variable n, where the very first bit (LSB) is labeled bit 1.