Monday, January 16, 2017

Challenge Accepted: Kill K-th Bit



This is my attempt at "Kill K-th Bit" on www.codefights.com



This was a pretty difficult challenge in the beginning. Once I started reviewing bitwise operations, I pretty much had a solution in mind.



At first, I kept getting errors because I was not complementing 1. So what was happening was when I shift 1 over the right amount of bits, then "AND" them together, the Kth bit in N was already 1 it didn't change because 1 + 1 = 1. The only way that I could make it zero is by inverting the shift so that only the Kth bit would change to 0. Meaning if 1 (in binary) shifted and became 00010000, I would have to complement it to make it 11101111 so that none of the other bits are altered. "I hope that made sense".



Challenge Accepted? The Challenge Accepted Video Series is documentation of my attempts on CodeFights Arcade Tasks and Challenges. This also gives good insight into what programmers do on a regular basis (as far as creating a single (or a few) method(s)/procedure(s)).

If you’ve come up with a better solution, log into CodeFights and post it.

https://codefights.com/signup/Cj6u5WynsJpu64RLk/main

No comments:

Post a Comment