PDA

View Full Version : Binary to Decimal Conversion



debonene
11-21-2009, 06:00 AM
Please can anyone tell me the command syntax to convert binary to decimal representation using the BS2 board.

Mike Green
11-21-2009, 06:11 AM
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..

SRLM
11-21-2009, 06:11 AM
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!...

debonene
11-21-2009, 06:25 AM
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 )

SRLM
11-21-2009, 07:49 AM
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 Allen
11-22-2009, 01:45 AM
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 (http://www.emesystems.com)

debonene
11-22-2009, 07:46 AM
Thank you Tracy Allen.