Shop OBEX P1 Docs P2 Docs Learn Events
Converting binary to decimal in a program — Parallax Forums

Converting binary to decimal in a program

ArchiverArchiver Posts: 46,084
edited 2000-11-26 09:26 in General Discussion
Hello,
Hi, I have a BS2 and I'm wondering if there is a command or something that
will convert an 8-bit binary number into decimal form? I'm familiar with
the calculations for manually figuring out the equivalent form, but I'm
sure there has to be a better way of converting without coding in all the
lines of code that would take. I want to use this decimal number within the
program to compare two light values from my a/d convertor / phototransistor
setup, so the debug modifier doesn't work for me in this case. Is it
possible to use the dec modifier for debug in another way to just convert
my binary number into decimal?

Thanks,
Mike, aka Flaming Headphones

ICQ: 17940917
E-mail: headphones99@i...

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-11-25 23:09
    At 03:57 PM 11/25/2000 -0700, you wrote:
    >Hello,
    >Hi, I have a BS2 and I'm wondering if there is a command or something that
    >will convert an 8-bit binary number into decimal form? I'm familiar with
    >the calculations for manually figuring out the equivalent form, but I'm
    >sure there has to be a better way of converting without coding in all the
    >lines of code that would take. I want to use this decimal number within
    >the program to compare two light values from my a/d convertor /
    >phototransistor setup, so the debug modifier doesn't work for me in this
    >case. Is it possible to use the dec modifier for debug in another way to
    >just convert my binary number into decimal?

    Debug CAN use modifiers. Check Page 253 of the Version 1.9 PBASIC Manual.

    >Thanks,
    >Mike, aka Flaming Headphones
    >
    >
    >ICQ: 17940917
    >E-mail: headphones99@i...
  • ArchiverArchiver Posts: 46,084
    edited 2000-11-26 09:26
    You may attribute to a new variable the binary form:
    x var byte (variable that will be read as decimal)

    x.bit0 = y.bit? (LSB of your binary number)
    x.bit1 = y.bit?
    ....
    x.bit7= y.bit? (MSB)

    or if your binary number is in the pins

    x.bit0 =INx
    .....
    ACJacques

    Flaming Headphones wrote:
    >
    > Hello,
    > Hi, I have a BS2 and I'm wondering if there is a command or something that
    > will convert an 8-bit binary number into decimal form? I'm familiar with
    > the calculations for manually figuring out the equivalent form, but I'm
    > sure there has to be a better way of converting without coding in all the
    > lines of code that would take. I want to use this decimal number within the
    > program to compare two light values from my a/d convertor / phototransistor
    > setup, so the debug modifier doesn't work for me in this case. Is it
    > possible to use the dec modifier for debug in another way to just convert
    > my binary number into decimal?
    >
    > Thanks,
    > Mike, aka Flaming Headphones
    >
    >
    > ICQ: 17940917
    > E-mail: headphones99@i...
Sign In or Register to comment.