xxxxxxxxxx
49
class ShiftRegister {
constructor(register = null) {
this.bit0 = 0;
this.bit1 = 0;
this.bit2 = 0;
this.bit3 = 0;
this.bit4 = 0;
this.bit5 = 0;
this.bit6 = 0;
this.bit7 = 0;
if (register) this.next = register;
}
push(bit) {
let last = this.bit7;
this.bit7 = this.bit6;
this.bit6 = this.bit5;
this.bit5 = this.bit4;
this.bit4 = this.bit3;
this.bit3 = this.bit2;
this.bit2 = this.bit1;
this.bit1 = this.bit0;
this.bit0 = bit;
if (this.next) this.next.push(last);
}
_toArray() {
return [
this.bit0,
this.bit1,
this.bit2,
this.bit3,
this.bit4,
this.bit5,
this.bit6,
this.bit7
];
}
toArray() {
let arr = [ this._toArray() ];
let next = this.next;
while (next) {
arr.push(next._toArray());
next = next.next;
}
return arr;
}
}