Quote Originally Posted by HenrikOlsson View Post
Hi Tony,
Each location or adress in the EEPROM is a byte, a byte is 8 bits. If you do WRITE 0, 15 you will write the value 15 to adress 0 of the EEPROM. If you read the value back into a variable the variable will contain the value 15, if you decide to "print" the value in binary you'll get 00001111, if you decide to print it in hex you'll get E - it's all the same just different ways for us humans to express it.

If I understand your example with the numbers 11 and 2 correct you want 11 to be stored in the high nibble and 2 in the low nibble, resulting in the full byte containing 10110010, if we express that number in decimal form it's 178. One way to go from your two numbers into a single byte could be:
Code:
FullByte = Number_1 * 16 + Number_2
See, 11*16+2=178.
(Multiplying by 16 can be replaced with four left-shifts so FullByte = (Number_1 << 4) + Number_2 which is kind of what Dave is doing.)

To get the value back into your two discrete variables you can do something like
Code:
Number_1 = FullByte >> 4  ' This will take the FullByte and shift it four steps to the left, the low nibble will be "pushed" out
Number_2 = FullByte & %00001111   ' This will mask the high nibble.
/Henrik.
Hi Henrik,

Thanks for the reply and explanation. What I'm trying to do is store two separate values. Each value can be incremented separately, that's why I need to be able to store digits separately, so they can't be misread. What I am seeking to do is store both values in one byte of eeprom. I am starting to understand how to shift them in and out, what I would like clarification on is when you say they are pushed out, does the value still stay in that byte of eeprom, or are the values shifted out like a shift register? I need to be able to go back to reference those numbers again and a again. If they are "shifted out" then they are gone, right?

It's easy to understand when you know the answer. This is my first time working with shifting, so I'm kind of curious how creative I can be to use these features. I am just trying to make the best use of space I can in eeprom.

The best analogy I can think of when trying to explain what I'm doing is like when working with a chart. You have so many blank entries on a page (eeprom available bytes). When you go to write your pairs of number in the blank spaces, if you enter one number on one blank line and the second on line two, you fill up the sheet twice as fast.

If you squeeze both numbers in on one line, you double the amount of data you can store, however you have to make some kind of separator to make sure the numbers are not merged together. We would normally put a space or a dash or slash when we write it, but for the pic we shift. This is what I've gathered so far from the replies. Does that sound about right?

Thanks for all the input guys.

Tony