Shop OBEX P1 Docs P2 Docs Learn Events
Binary to Decimal Conversion — Parallax Forums

Binary to Decimal Conversion

debonenedebonene Posts: 19
edited 2009-11-22 00:46 in BASIC Stamp
Please can anyone tell me the command syntax to convert binary to decimal representation using the BS2 board.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-20 23:11
    There are several different ways to do what you want. The place to look for a detailed explanation and examples is in the BASIC Stamp Syntax and Reference Manual or in the help files of the Stamp Editor.

    There's an operator DIG used to provide a decimal digit of the decimal representation of a number.

    There's what's called the DEC formatter used in a variety of I/O statements including SERIN, SEROUT, DEBUG, and DEBUGIN among others. The various formatters are also discussed in one of the appendices of the Manual..
  • SRLMSRLM Posts: 5,045
    edited 2009-11-20 23:11
    Constants when coding? Outputting with a serial command? Doing something else? We need more information on what you intend to do.

    edit: Mike! You did it again!...
  • debonenedebonene Posts: 19
    edited 2009-11-20 23:25
    For example : My result3 in Line1: is in Binary representation, and I am trying to do a conversion to mill volts using Line 2 statement. My result in Line2 is not correct because I am mixing Binary and decimal value all together. So I would like to convert my Binary result to Decimal before proceeding with Line 2.
    Verification: I kept a Debug command after Line1 and Line2 and it gave me different answers. such as
    result3= 3918( This is correct)
    mVolts3= 0006(This is not correct)


    CODE: .......
    Line 1: result3 = result3 & value3
    Line 2: mVolts3 = ((result3 *5000)/4095 )
  • SRLMSRLM Posts: 5,045
    edited 2009-11-21 00:49
    debonene,

    You have to try harder than that. Give us something to work with: attach the full source code, with comments on each line where you think it should be decimal or binary and include what you are trying to do.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-11-21 18:45
    If result3=3918, then you will have to use different math to convert to millivolts. The formula, 3918 * 5000, overflows the 16 bit limit. Are the values 5000 and 4095 constants? It looks like conversion of a 12 bit ADC reading with a 5 V reference. If so, try one of the following formulae:

    mVolts3 = result3 */ 313

    or

    mVolts3 = result3 ** 14484 + result3 ' more accurate

    See */ and ** operators in the PBASIC reference materials.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • debonenedebonene Posts: 19
    edited 2009-11-22 00:46
    Thank you Tracy Allen.
Sign In or Register to comment.