Number of Bits Needed to Represent a Zero-Offset Integer

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 19 11:43:13 PST 2015


On Monday, January 19, 2015 13:37:12 Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 1/19/15 12:35 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > On Monday, January 19, 2015 08:30:47 Steven Schveighoffer via Digitalmars-d-learn wrote:
> >> http://dlang.org/phobos/core_bitop.html#.bsr
> >>
> >> It's actually an intrinsic, reduces to an instruction. Mind the
> >> requirements for 0.
> >
> > Sadly, I don't think that it have occurred to me from just reading the docs
> > that that function would tell you how many bits it took to hold the value -
> > though I don't know what else you'd use it for. In any case, thanks for the
> > tip.
> >
> > - Jonathan M Davis
> >
>
> It tells you the most significant bit that is set. That is what you are
> looking for, no?

Yes. But if I'm looking for a function that tells me how many bits are
required to hold a value, I'm thinking about how many bits are required, not
what the most significant bit is. Ultimately, it's the same thing, but it's
looking at it from a different perspective, so I don't think that I would
have caught it.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list