Given an unsigned word x, produce a word (same width) that has a single 0-bit located at the position of the rightmost set bit (rightmost 1) in x, and 1 bits everywhere else. If x is all zeros, the result should be a word of all ones.
Input: x =0b01011000Output: 0b11110111Explanation: rightmost `1`in`x`is at bit position 3(0-based from LSB); resulting word has a single 0 there and 1s elsewhere.
x - 1 clears the rightmost set bit of x and sets all less-significant bits to 1. The bitwise complement ~x has 0 where x has 1. At the position of the rightmost set bit both ~x and (x - 1) have a 0. OR-ing them produces a single 0 at that position and 1 everywhere else. For an all-zero input, x - 1 (as unsigned) wraps to all ones and ~x is also all ones, so the OR is all ones.