Saving rotary encoder data for next power up

If you line them up at A0, A1, A2, A3 you can read them in one go:

byte tempIn = PINC & 0x0F; // read the encoder, 4 bits

A print here will allow you to read the numbers to build the grayTable.

Now you use the array:

newPosition = grayTable[tempIn]; // translate to position, mind the square hooks

It can even be combined:

newPosition = grayTable[PINC & 0x0F];

Setting the pull-up resistors is also simple:

PORTC |= 0x0F; // pull-ups at A0 A1 A2 A3

Declaration of the table:

byte grayTable[] = {0, 0x01, 0x03, 0x02, … }; // example, adapt to your encoder, needs 16 numbers, either hex or decimal

If the bit that is changing bounces, the difference will be only 1 step in the position, that is the advantage of Gray Code.

This is not necessaraly portable to another board anymore, but adapting is easy.

If you still use pins 8, 9, 10, 11 make it PINB and PORTB.