PDA

View Full Version : Convert a word variable to decimal



Tomexx
- 4th December 2004, 02:09
Hi,
I searched the forums and haven't found the answer. I came across a nice thread where Melanie explains how to preset a value to the EEPROM and later read it back. I need something slightly different:

1. ask user for a 4-digit decimal number (WORD variable)
2. store it to EEPROM using WRITE
3. on next power up READ the number into a WORD variable as a decimal number

I can do number 1 & 2.

But when it comes to READing the stored password I don't know how to convert it from the 2 hex bytes back to a 4-digit decimal number (stored in a WORD)



myVar VAR WORD
READ 0, myVar.BYTE0
READ 1, myVar.BYTE1


But how do I get a decimal number from that is beyond me.

Thanks,
Tom

Melanie
- 4th December 2004, 20:02
Try this...

MyVar var WORD

To save the word into two consecutive byte addresses (0 and 1) in EEPROM...

WRITE 0,MyWord.HighByte
WRITE 1,MyWord.LowByte

on power-up (or whenever) when you need to read back, just do the opposite...

READ 0,MyWord.HighByte
READ 1,MyWord.LowByte