AND , OR Pattern, Make maximum

 

if we AND 1 & 3 at least last bit will set as they both odd, then OR with 6 will result 0111->7

now 7(0111) & 7 = 7

lastly OR with 8(1000) will result all bit set and highest value

Upto 15 — 2^4-1 is MSB=4(consist 4 total bit)

after 16 we need 5 bit…….so on

int x=__lg(n) (MSB) 15–>3

For Odd Case: solve(n-1) & n , n-1 will give n, and n&n=n

Example for n=7, 7&7=7 will be the highest

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top