Page 1 of 1

Over 8-bit EEPROM usage

Posted: Sun Apr 25, 2010 7:45 pm
by Motions
I'm playing with the sample EEPROM code and can't fully wrap my head around how the registers work.

The code incluides:

Code: Select all

Data_In = DIN & 0xFF
Data_In2 = DIN >> 8
First, what does the & 0xFF mean?
I know that >> means to shift right but don't have the fundamental idea of what it means. If you had a 32-bit value, how would the code look then?

Just trying to get a very basic understanding of how it works. Obviously, I'm extremely new.

Re: Over 8-bit EEPROM usage

Posted: Mon Apr 26, 2010 10:44 am
by Benj
Hello,

variable & 0xff

This code is a logic and of the variable and 0xff.

0xff is a hexadecimal number but you could instead use 255 or 0b11111111.

A logical AND is used as a mask where bit 0 is anded with bit 0 and bit 1 is anded with bit 1 etc.

For example

variable & 0x01
variable & 1
variable & 0b00000001

would be 0 if bit 1 of variable was a 0 and would be 1 if bit 1 of variable was a 1.

0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1

This article may help to explain things.

http://www.matrixmultimedia.com/mmforum ... =26&t=4792

If DIN is a 16-bit number eg a short or an int then shifting to the right by 8 places will move the upper 8-bits of the variable down to the lower 8-bits to allow you to save the value into a byte register.