How we got b equal 2^i-1 .please suggest another way

how b is calculated when we are doing bits clearation from i to j is there any other way to calculate value of b

Hey @guptanikhil898
N=00011111
we want to create mask like 11110001
this mask can be created using or of two masks

  1. 11110000
  2. 00000001

to make 1) left shift all ones by j+1
11111111 (~0)
(~0)<<(j+1) ==> 11110000

to make 2) left shift all ones by i and then take negation
((~0)<<i) ==> 11111110
now take not of this
~(((~0)<<i)) ===> 00000001

now take or of two
[ (~0)<<(j+1) ] || [ ~(((~0)<<i)) ] ==> 11110001

in this way we created mask

if you want to ask something about this feel free to ask
i hope this helps
if yes show your response with :heart: and don’t forgot to mark doubt as resolved

Hey @guptanikhil898
If u don’t have any further doubt in this then please mark it as resolved :slight_smile: