Boost logo

Boost :

From: Matt Calabrese (rivorus_at_[hidden])
Date: 2005-09-04 23:55:08


On 9/3/05, Matt Calabrese <rivorus_at_[hidden]> wrote:
>
>
> On 9/2/05, Paul Mensonides <pmenso57_at_[hidden]> wrote:
>
> > The problem is that there isn't any arbitrary precision arithmetic
> > support in
> > the pp-lib. If there was, you could do better than that for syntax:
> >
> > BOOST_BINARY_INT( 1100 0011 1010 )
> >
>
> I do not immediately see how to implement it allowing the syntax you
> describe (where your nibbles are simply separated by spaces rather than
> using a Boost.Preprocessor sequence), so if you could, please enlighten me
> as I know you must be more experienced with the preprocessor (I love
> Boost.Preprocessor by the way).

Nevermind, I figured out a way to do it myself with lots of macro magic. A
version allowing the more simple syntax you originally alluded to is
available here:

http://www.illegal-immigration.com/Riv/boost/binary_literal.hpp

Also, I changed the macro name to BOOST_BINARY_LITERAL

Usage is as simple as:

BOOST_BINARY_LITERAL( 101 0111 1010 0110 )

The first nibble is allowed to be written with under 4 explicit bits, but
the remaining nibbles must use a complete 4 bits each. This was done to
avoid confusion.

If you wish to append standard integer suffixes, you can use the macro
BOOST_SUFFIXED_BINARY_LITERAL

Usage for that is:

BOOST_SUFFIXED_BINARY_LITERAL( 101 0111 1010 0110, UL )

It should work for integers of any reasonable size, even well beyond 64
bits, and results in a hex literal at preprocessing time.

-- 
-Matt Calabrese

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk