/*
  Binary Decoder with 74HC595 Shift Register
*/
const int DATA_PIN  = 2;
const int LATCH_PIN = 3;
const int CLOCK_PIN = 4;
const int SW_PINS[3] = {A2, A1, A0};
int oldBits = -1;
void updateShift(int value) {
  // allow the 595 to update
  digitalWrite(LATCH_PIN, LOW);
  // send 8 bits
  shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, value);
  // latch the data
  digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
  Serial.begin(115200);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  for (int i = 0; i < 3; i++) {
    pinMode(SW_PINS[i], INPUT_PULLUP);
  }
}
void loop() {
  int bits = 0;
  // Read the switches and raise to power
  for (int i = 0; i < 3; i++) {
    bits = bits + (!digitalRead(SW_PINS[i]) * (1 << i));
  }
  if (bits != oldBits)  {
    oldBits = bits;
    int count = 1 << bits;
    Serial.print("Bits value: ");
    Serial.print(bits);
    Serial.print("\tShift value: ");
    Serial.println(count);
    updateShift(count);
    delay(20);  // debounce
  }
}
Bit 0 -- 1 --  2
0
1
2
3
4
5
6
7