Convert a word variable to decimal


Closed Thread
Results 1 to 2 of 2
  1. #1
    Tomexx's Avatar
    Tomexx Guest

    Default Convert a word variable to decimal

    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)

    Code:
    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  2. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts