I want to find a bit mask with only first bit set to 1 but mask length has to be determined dynamically taking in consideration number n.
For example if n = 161
161 in binary format is 10100001
Determined mask should be 10000000
So it can be compared like this:
10100001
10000000
Second example, n = 34
34 in binary format is 100010
Determined mask should be 100000
So it can be compared like this:
100010
100000
There is certainly mathematical solution to this and maybe even purely by moving bits around but I can't find solution in any of the two ways, so any help is appreciated.
Thank you.