View Full Version : Binary to Decimal Conversion
11-21-2009, 06:00 AM
Please can anyone tell me the command syntax to convert binary to decimal representation using the BS2 board.
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..
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!...
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)
Line 1: result3 = result3 & value3
Line 2: mVolts3 = ((result3 *5000)/4095 )
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.
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
mVolts3 = result3 ** 14484 + result3 ' more accurate
See */ and ** operators in the PBASIC reference materials.
11-22-2009, 07:46 AM
Thank you Tracy Allen.