Browsing the topic Bit Magic
May 30, 2009
Parity: Parity of a number refers to whether it contains an odd or even number of 1-bits. The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits. Main idea of the below solution is – Loop while n is not 0 and [...]
Read More »The very first solution that comes to our mind is the one that we learned in school. If sum of digits in a number is multiple of 3 then number is multiple of 3 e.g., for 612 sum of digits is 9 so it’s a multiple of 3. But this solution is not efficient.
Read More »May 28, 2009
Write a function that, for a given no n, finds a number p which is greater than or equal to n and is a power of 2.
Read More »