>I did encounter a strange problem in my C program, and traced it down;

>it looks like I get different results for bit left shifts when the bit

count is a constant or a funtion-return value.

When doing (1 << 32) for a 32-bit-unsigned I expect to get 0;

The behaviour is undefined if the number of bits by which you are

shifting is >= the number of bits in the object.

Ok, thank you!

What I'm trying to do is this: I've got some unsigned type, and a

function which returns a number of bits <= the number of usable bits of

this type.

I need to calculate (1 << getBits())-1, i.e., set the lower getBits()

bits to one (which might be all ones if it is equal to the type's width,

but it also might be only some less-significant-bits ones).

Is there some other clever way to do this?

Thanks,

Daniel

--

Got two Dear-Daniel-Instant Messages

by MSN, associate ICQ with stress--so

please use good, old E-MAIL!