Shop OBEX P1 Docs P2 Docs Learn Events
HEX to DEC? — Parallax Forums

HEX to DEC?

computer guycomputer guy Posts: 1,113
edited 2010-04-20 06:41 in Propeller 1
Hello,


What is the easiest way to convert a HEX number (i.e $F4) to the decimal equivelant (i.e. 244)?


Thank you smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-20 05:25
    Where and how are you getting the hex numbers? Remember that, when you compile a program, all numbers that are part of the program are just numeric values and compiled into bytes. They're neither decimal nor hexadecimal nor binary. They're just numbers. Hexadecimal and decimal are representations of numbers for display purposes (or for manual entry).
  • computer guycomputer guy Posts: 1,113
    edited 2010-04-20 05:32
    Hi Mike,

    They are being received as a byte via Full Duplex Serial.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
  • computer guycomputer guy Posts: 1,113
    edited 2010-04-20 06:09
    I think I get what you mean though.

    If I say this:
    num := $F4
    
    if num == 244
      ser.str(string("Success!!!"))
    
    



    It will put "Success!!!" to the serial line, because 244 is another representation of $F4 and therefore num == 244.
    Is this correct?

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
  • computer guycomputer guy Posts: 1,113
    edited 2010-04-20 06:33
    One last thing. How do I do a percentage on the prop?

    The prop can't handle decimals so if I do. (15/16)*100 to get 93%
    It ends up doing 15/16 which it calculates to be 0 because it ignores decimals, 0 * 100 is 0. So I get 0%

    There is a huge difference between 93% and 0% tongue.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
  • computer guycomputer guy Posts: 1,113
    edited 2010-04-20 06:41
    I'm having a really good day. I just realised that if I rearange it to be (15*100)/16 I get the same percentage but with math that the prop can handle.

    yay!! hop.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
Sign In or Register to comment.