

#include "bits/grsnegative.h"
#include "bits/parity.h"

#include "bits/printbin.h"

#include "fxttypes.h"
#include "fxtiomanip.h"
#include "demo/nextarg.h"


//% The Golay-Rudin-Shapiro (GRS) sequence.


int
main(int argc, char **argv)
{
    ulong n =5;
    NXARG(n, "Number of bits");

    ulong nn = 1UL << n;
    int pd = (int)n + 2;

    cout << setw(4) << "k" << ":  ";
    cout << setw(pd+4) << "bin(k) ";
    cout << "  GRS(k) ";
    cout << setw(pd+4) << "k&(k>>1) ";
    cout << setw(pd+4) << "inverse_gray(k&(k>>1)) ";
    cout << endl;

    for (ulong k=0; k<nn; ++k)
    {
        const ulong ka = k & (k>>1);
        cout << setw(4) << k << ":  ";
        print_bin("    ", k, pd);
        cout << "    " << grs_negative_q(k) << " ";
        print_bin("     ", ka, pd);
        print_bin("     ", inverse_gray_code(ka) , pd);

        cout << endl;
    }

    return 0;
}
// -------------------------


/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/bits"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/bits/grs-demo.cc"
/// make-target2: "1demo DSRC=demo/bits/grs-demo.cc DEMOFLAGS=-DTIMING"
/// End:

