Over 8-bit EEPROM usage

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Motions
Posts: 10
Joined: Sun Apr 11, 2010 2:20 pm

Over 8-bit EEPROM usage

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Over 8-bit EEPROM usage

Post 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.

Post Reply