Shop OBEX P1 Docs P2 Docs Learn Events
Hex Value $24 to DEC value 24 — Parallax Forums

Hex Value $24 to DEC value 24

HumpeHumpe Posts: 10
edited 2007-12-17 18:28 in BASIC Stamp
Hi

I have encoutered a small problem. The output from my clock is in HEX, $24 is the minutes or seconds in DEC 24. Now i want to represent the output value binary with diods but of course it doesnt get quite right.

I need to transform the value $24 to the decimal value 24 (or the binary value 24). Is there short solution for this with Pbasic ?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-17 17:50
    Your hex value is "binary-coded decimal" (BCD). Here's the code to convert:

    decimal = bcd >> 4 * 10 + (bcd & $0F)
    
    
    


    -Phil
  • HumpeHumpe Posts: 10
    edited 2007-12-17 17:59
    Thanks a lot Phil.



    (You dont want to see my lookup table for this :-))
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-12-17 18:00
    or
    decimal = bcd.nib1*10+bcd.nib0
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-17 18:28
    Tracy,

    I'll see your twelve bytes and raise you four! ('Forgot about the NIBs!)
    ___________

    Humpe,

    Use Tracy's method. It generates less code.

    -Phil
Sign In or Register to comment.