Ho can I check if the most (or least) significant bit of a value is set?
Printable View
Ho can I check if the most (or least) significant bit of a value is set?
low bit
x & 1
hi bit
x & y
or to return a value 1 or 0
x >> z
where
z=(sizeof(x)-1)*8
and
y is 2^z
That will do.
Thanks kedaman.
:)
I took a closer look at it and came up with this
z=sizeof(x)*8 - 1
rather than what you wrote.
I'll assume this is what you meant.
thanks anyway; I got the idea. :)
yeah that's it :)
x was of course meant to be the type of x, but since you got the idea, everythign is :) the compiler may or may not optimize it though, so you'd better evaluate z