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:

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

Usage for that is:


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, gregod at, cpdaniel at, john at