I'm doing practice of bit manipulation in arduino with a 74HC595 shift register. I would like to create an algorithm that allows the binary digit to perform this way:
1 0 0 0 0 0 0 1
0 1 0 0 0 0 1 0
0 0 1 0 0 1 0 0
.
.
.
- 1 0 0 0 0 0 0 1
How can I perform this type of shifting? I don't have any fluency thinking this type of operation, I have only performed a circular shift with "an algorithm" like:
myByte = myByte*128 + myByte/2
But I don't know how to perform the output that I showed.
How can I do this? Thanks
Update1:
This is how is wired the circuit
and this is the code that I use to perform a circular shift.
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;
int dt = 800;
byte myByte = 0b00000001; //in BIN
void setup() {
Serial.begin(9600);
pinMode(latchPin,OUTPUT);
pinMode(dataPin,OUTPUT);
pinMode(clockPin,OUTPUT);
}
//circular shift to the left
void loop() {
digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,LSBFIRST,myByte);
digitalWrite(latchPin,HIGH);
Serial.print("BIN: ");
Serial.print(myByte,BIN);
Serial.print(" --> ");
Serial.print("HEX: ");
Serial.print(myByte,HEX);
Serial.print(" --> ");
Serial.print("DEC: ");
Serial.println(myByte,DEC);
myByte = myByte/128 + myByte*2; //shift by left //using MSBFIRST
delay(dt);
}
<<
and>>
and the bitwise OR|
. All that you need. Also, off-topic here: \$\endgroup\$10000001
= 128 + 1 ....01000010
= 64 + 2 ....00100100
= 32 + 4 .... etc .... all you need is onefor
loop \$\endgroup\$