Tag: Bit Hacks

Bit Hacks – Part 5 (Find absolute value of an integer without branching)

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)

Bit Hacks – Part 4 (Playing with letters of English alphabet)

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)