unsigned long now;
unsigned int counter;
# define RATE 10000
void setup() {
Serial.begin(115200);
Serial.println("hi Mom!");
Serial.println("advance kAdvance");
}
unsigned int zit = 0x8011;
unsigned int it = 0xcd55;
void loop() {
static unsigned long lastTime;
now = millis();
// loop rate
it = reverseK16(it);
Serial.print(it, HEX);
Serial.println("");
//zit = reverseK(zit);
static int fork;
if (++fork > 50) for (; ; );
// once per
if (now - lastTime < RATE) return;
lastTime = now;
// Serial.println(counter); counter++;
}
// the original Moberly advance
unsigned int advance(unsigned int it)
{
it <<= 1;
if (it & (1ul << 15)) // 0x8000ul, gack! chain reaction interesting affect
if (it & (1 << 14)); else it |= 1; // <--
else if (it & (1 << 14)) it |= 1;
if (0) {
static int counter;
Serial.print(counter); Serial.print(" ");
counter++;
unsigned int the = it & 0xffff;
Serial.println(the, HEX);
}
return it;
}
unsigned int advanceK(unsigned int it)
{
unsigned int bits = it & 0x6000;
bool parity = false;
while (bits) {
bits &= bits - 1;
parity = !parity;
}
it <<= 1;
if (parity) it |= 0x1;
return it;
}
unsigned int reverseK(unsigned int it)
{
unsigned int bits = it & 0x8002;
bool parity = false;
while (bits) {
bits &= bits - 1;
parity = !parity;
}
it >>= 1;
if (parity) it |= 0x8000;
return it;
}
void mobe16()
{
if (digitalRead(3) == HIGH) it = advanceK16(it);
else it = reverseK16(it);
}
unsigned int advanceK16(unsigned int it)
{
unsigned int bits = it & 0xb400;
bool parity = false;
while (bits) {
bits &= bits - 1;
parity = !parity;
}
it <<= 1;
if (parity) it |= 0x1;
return it;
}
unsigned int reverseK16(unsigned int it)
{
unsigned int bits = it & 0x6801;
bool parity = false;
while (bits) {
bits &= bits - 1;
parity = !parity;
}
it >>= 1;
if (parity) it |= 0x8000;
return it;
}
void advance16()
{
unsigned char a = it & (1ul << 15) ? 1 : 0; // 15 (16/1)
unsigned char b = it & (1 << 13) ? 1 : 0; // 13 (14/1)
unsigned char c = it & (1 << 12) ? 1 : 0; // 12 (13/1)
unsigned char d = it & (1 << 10) ? 1 : 0; // 10 (11/1)
// unsigned char e = a ^ b ^ c ^ d;
unsigned char e = a + b + c + d;
it <<= 1;
if (e & 1) it |= 0x1;
}
/*
original advance looks correct
hi Mom!
400
800
1000
2000
4001
8003
6
C
18
30
60
C0
180
300
600
C00
1800
3000
6001
C002
8005
A
14
28
50
A0
advanceK looks good
hi Mom!
advance kAdvance
800 800
1000 1000
2000 2000
4001 4001
8003 8003
6 6
C C
18 18
30 30
60 60
C0 C0
180 180
300 300
600 600
C00 C00
1800 1800
3000 3000
6001 6001
C002 C002
8005 8005
A A
14 14
28 28
50 50
A0 A0
140 140
*/