Need help for subroutine

OK, here is what I need to do. I am not a mathmatician, but here goes:

I want to have a 16 bit binary number. I want to store it somewhere , maybe eprom.
I want to be able to read anyone of the 16 bits.
I want to be able to write to anyone of the 16 bits.
How would I MASK individual bits in order to do this?

I need to know how to isolate each individual bit.

I am not knowlegable in this area.

Thanks!
:slight_smile:

To check on a particular bit:

if (variable & (1<<7)) { ... // See if bit 7 is set

To modify a particular bit:

variable |= (1<<7);  // Set bit 7, leave all other bits alone
variable &= ~(1<<7);  // Clear bit 7, leave all other bits alone

Thanks so much for the info