-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrayCodeGenerator.cpp
More file actions
92 lines (74 loc) · 2.67 KB
/
Copy pathGrayCodeGenerator.cpp
File metadata and controls
92 lines (74 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
Copyright © 2024 Claus Vind-Andreasen
This program is free software; you can redistribute it and /or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 - 1307 USA
This General Public License does not permit incorporating your program into proprietary programs.If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library.
If this is what you want to do, use the GNU Library General Public License instead of this License.
*/
// GrayCodeGenerator.cpp : This file contains the 'main' function, which is a teestprogram for the GrayCodeeGeneratorClass
//
#include <iostream>
#include "GrayCodeGenerator.h"
#define WIDTH 8
void putBit(int w, u64 x)
{
if (w>1)
{
putBit(w - 1, x >> 1);
}
printf("%c", x & 1 ? '1' : '0');
}
#ifdef OS_WINDOWS
#define FSTRING "I64"
#else
#define FSTRING "l"
#endif
int main()
{
GrayCodeGeneratorClass GC;
GC.Init(WIDTH, 0x7FFFFFFAA);
u64 o= 0, oold= 0;
for (u64 i = 0; i <= (((u64) 1) << WIDTH); i++) {
o = GC.Next();
printf(" %8" FSTRING "d %8" FSTRING "X ",i, o );
putBit(WIDTH, o);
printf(" ");
putBit(WIDTH, o^oold);
oold = o;
printf("\n");
}
printf("\n");
printf("\n");
GC.Init(WIDTH, 0x7FFFFFFAA);
for (u64 i = 0; i <= (((u64)1) << WIDTH); i++) {
o = GC.Previous();
printf(" %8" FSTRING "d %8" FSTRING "X ", i, o);
putBit(WIDTH, o);
printf(" ");
putBit(WIDTH, o ^ oold);
oold = o;
printf("\n");
}
printf("\n");
printf("\n");
GC.Init(WIDTH, 0x7FFFFFFAA);
for (u64 i = 0; i <= (((u64)1) << WIDTH); i++) {
o = GC.Next();
printf(" %8" FSTRING "d %8" FSTRING "X ", i, o);
putBit(WIDTH, o);
printf(" ");
putBit(WIDTH, o ^ oold);
oold = o;
printf("\n");
o = GC.Previous();
printf(" %8" FSTRING "d %8" FSTRING "X ", i, o);
putBit(WIDTH, o);
printf(" ");
putBit(WIDTH, o ^ oold);
oold = o;
printf("\n");
}
printf("\n");
printf("\n");
}