## Check if given number is power of 4 or not

Given a number, check if it is power of four or not.

Read More Check if given number is power of 4 or notCoding made easy

Given a number, check if it is power of four or not.

Read More Check if given number is power of 4 or notGiven an integer, swap consecutive b bits starting from given positions in binary representation of the integer. The bits to be swapped should not overlap with each other.

Read More Swap individual bits at given position in an integerGiven a number n, find previous power of 2. If n itself is a power of 2, return n.

Read More Round up to the previous power of 2Given a number n, find next highest power of 2. If n itself is a power of 2, return n.

Read More Round up to the next highest power of 2Given two 16-bit positive values stored in 32-bit integer variables, find the product using the 8-bit multiply operator that that takes two 8-bit numbers and returns a 16-bit value.

Read More Multiply 16-bit integers using 8-bit multiplierGiven two integers, find their minimum and maximum without using branching.

Read More Find the minimum or maximum of two integers without using branchingGiven an integer, count set bits in it.

Read More Count set bits using lookup tableGiven an integer, calculate its Parity. The parity refers to the number of 1’s in a given binary number. Odd parity (encoded as 1) means there are an odd number of 1’s and even parity (encoded as 0) means that there are an even number of 1’s. Parity bits are often used as a …

Read More Compute parity of a number using lookup tableGiven an integer, count its set bits.

Read More Brian Kernighanâ€™s Algorithm to count set bits in an integerIn this post, we will discuss few unrelated problems that can be solved using bit manipulation hacks. Below Problems are covered in this post – Problem 1. Find number of bits needed to be flipped to convert given integer to another Problem 2. Conditionally negate a value without branching Problem 3. Find XOR of …

Read More Bit Hacks – Part 6 (Random Problems)Given an integer, compute its absolute value (abs) without branching We can use the expression ((n + mask) ^ mask) where mask is (n >> 31) (assuming 32 bit storage for integers) to compute the absolute value of n. The mask (n >> 31) will be evaluated to 0 for positive numbers and …

Read More Bit Hacks – Part 5 (Find absolute value of an integer without branching)In this post we will discuss some of the bit hacks/tricks on letters of English alphabet. Below tricks are covered in this post – Trick 1. Convert uppercase character to lowercase Trick 2. Convert lowercase character to uppercase Trick 3. Invert alphabet’s case Trick 4. Find letter’s position in alphabet Trick 1. …

Read More Bit Hacks – Part 4 (Playing with letters of English alphabet)In this post we will discuss few related problems that are related to unsetting the rightmost set bit of a number. How to unset the rightmost set bit of a number? The expression (n & (n – 1)) will turn off the rightmost set bit of given number. (n – 1) will have all …

Read More Bit Hacks – Part 3 (Playing with rightmost set bit of a number)In this post we will discuss few related problems that operates on the k’th bit of a number. Below problems are covered in this post – Problem 1. Turn off kth bit in a number Problem 2. Turn on kth bit in a number Problem 3. Check if kth bit is set for a …

Read More Bit Hacks – Part 2 (Playing with k’th bit)