Shop OBEX P1 Docs P2 Docs Learn Events
Hex minus Dec Problem — Parallax Forums

Hex minus Dec Problem

Sutton MurraySutton Murray Posts: 88
edited 2008-08-10 10:25 in BASIC Stamp
Greetings

I am battling with minimizing two varibles from each other.
The first varible is loaded with a byte from the DS1302(hours) and the second varible byte·is loaded from the stamps EEProm.
When the two is minimized from each other the sum value is incorrect. ( IHours = Hours - IHours)
My thoughts are that·this is as a result that the information retrieved from the EEProm is·in Hex, where that from the DS1302 is in·Dec. Is my thinking·correct in this area?

How will one convert one to a other to do the sum calculation?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For in much wisdom is much grief, and he who increases knowledge increases sorrow." ~Ecclesiastes 1:18

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-09 22:54
    The value in the DS1302 is not really "hex". It's what's called BCD (binary coded decimal). To convert a BCD byte to a binary result (or decimal ... it's all the same internally), do: result = bcdbyte.nib1 * 10 + bcdbyte.nib0
    The ".nib0"/".nib1" notation is described in the Stamp Manual and it allows you to access the most significant 4 bits and the least significant 4 bits of a byte.

    To go back, do: bcdbyte = (binary DIG 1) << 4 + (binary DIG 0)

    Look in the Manual for the descriptions of the DIG and << operators.
  • Sutton MurraySutton Murray Posts: 88
    edited 2008-08-10 10:25
    Mike

    Battle to understand your script at first, but am making it up. I am now buzy going through Jon Williams "It's time to get real with the dallas 1302". Your line is more advanced(understand how this works), but i will get their.
    Thanks for putting me on the right track.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For in much wisdom is much grief, and he who increases knowledge increases sorrow." ~Ecclesiastes 1:18
Sign In or Register to comment.