In order to stop the Mad Coder evil genius you need to decipher the encrypted message he sent to his minions. The message contains several numbers that, when typed into a supercomputer, will launch a missile into the sky blocking out the sun, and making all the people on Earth grumpy and sad. You figured out that some numbers have a modified single digit in their binary representation. More specifically, in the given number n the kth bit from the right was initially set to 0, but its current value might be different. It's now up to you to write a function that will change the kth bit of n back to 0.In order to stop the Mad Coder evil genius you need to decipher the encrypted message he sent to his minions. The message contains several numbers that, when typed into a supercomputer, will launch a missile into the sky blocking out the sun, and making all the people on Earth grumpy and sad. |
code>>
int killKthBit(int n, int k) {
return n & ~(1 << (k - 1));
}
'알고리즘 > codefights' 카테고리의 다른 글
19>rangeBitCount (0) | 2021.04.17 |
---|---|
18>arrayPacking (0) | 2021.04.17 |
Challenge>formatString (0) | 2019.03.06 |
Challenge>fibonacciIndex (0) | 2019.03.06 |
16>metroCard (0) | 2019.02.24 |