Boost logo

Boost Users :

Subject: Re: [Boost-users] max value by the number of bits
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-02-05 13:10:46


Le 05/02/13 16:27, Christian Henning a écrit :
>>> Is there a better way in boost?
>>
>> Try boost::low_bits_mask_t
>> http://tinyurl.com/bcy22xf
>>
> Mhmm, I don't see how that works. How do I get the max value from a
> low_bit_mask_t? It should be 2^n-1 with n being the number the bits.
>
>

low_bits_mask_t<Bits>::sig_bits is defined as
  (~( ~(unsigned_int(0u )) << Bits )) )

which is equivalent to 2^Bits-1 without risk of overflow.

Vicente


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net