I don't understand the part of EEPROM tutorial

Hi,
There are some lines in the EEPROM tutorial that I don't understand,
they are the ones in the image below:

What do they mean with "This will make your code portable to all AVR processors."

and also:
" As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1."

What does this even mean?

My native language isn't English and google translator isn't helping me much.

F1_:
What do they mean with "This will make your code portable to all AVR processors."

Different models of microcontroller have different EEPROM sizes. For example, the ATmega328P used on the Uno, Nano, and Pro Mini has 1 kB of EEPROM. The ATmega2560 used on the Mega has 4 kB of EEPROM. EEPROM.length() returns the EEPROM size of the specific microcontroller you're compiling for so this means your code will automatically adapt to each microcontroller. Much better than hardcoding in 1 kB or 4 kB, which makes it only work correctly on a few boards.

F1_:
and also:
" As the EEPROM sizes are powers of two,

What does this even mean?

EEPROM size refers to number of byte oriented locations inside it, and it (the size) is determined by the number of address lines.

If the EEPROM has 1 address line, the size is 21 = 2 locations
If the EEPROM has 2 address lines, the size is 22 = 4 locations
...
...
If the EEPROM has 10 address lines, the size is 210 = 1024 locations = 1 kbyte

The above chart says that the EEPROM size is power of two (Base is 2 and the power is address line)

Got it, Thanks pert and Golam!

F1_:
Got it, Thanks pert and Golam!

Meaning for one more item is left behind? Some one else will clarify it?

F1_:
and also:
" [...], wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1."

What does this even mean?

GolamMostafa:
Meaning for one more item is left behind? Some one else will clarify it?

F1_:
" As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1."

A simplified example:

Length of EEPROM is 16 bytes.
A byte sized variable holding the number 16 looks like 00010000 in binary.
Take 1 away from the length and you get 00001111 or 15 decimal, which is the last index into the EEPROM since indexes are 0->15.
So, if you want to automatically wrap around your index when it hits 16 you can use 15 as a mask, ie. 00010000 & 00001111 equals 00000000.
Other values remain unchanged, eg. 00000110 & 00001111 equals 00000110.

F1_:
" As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1."

A bitwise-and of the address and eeprom length - 1 will ensure that an address used is a valid EEPROM address, and that if you specify an address that is out of range, it will "wrap around" to the beginning of the EEPROM (say length is 1024, 0b00000010000000, subtract 1, you get 0b0000000111111111. And then you try to write to address 1024, which is out of range (since addresses start at 0, when length = 1024, valid addresses are 0~1023) - bitwise and with (length-1) will turn that into address 0, which is valid, instead of trying to tell the AVR to write to an invalid address). I think this behavior is bad, personally - I'd rather it not write anything if I tell it to write to an invalid address, rather than scribbling over other parts of the eeprom.

That said - by my reading of the datasheet, the above is redundant - the unused bits of the EEPROM address register are not enabled, so if it charges ahead blindly and writes the invalid address to the registers, the bits outside the valid range will not be saved, giving the same result as if you'd bitwise anded with length-1.

So to sum up, "0 counts", that "length -1" is just to ensure I won't write something to an invalid address like 1024 in a 1KB memory, got it!
Thanks, DrAzzy, arduarn and Golam!