Question regarding 74HC164 74HC165 shift registers 8x8 Button Grid value readout

Try this:

    // 164
    shiftOut(dataPin, clockPin, MSBFIRST, ~(1 << i));