PDA

View Full Version : Math problem on 16F688



PlantBob
- 14th June 2008, 18:23
When I use this statement:
hserout [dec (12 * 10000),$0D, $0A] the result is 54464.

Why is the math not working?

paul borgmeier
- 14th June 2008, 18:42
The math is working great - you overflowed (went beyond 16 bits)

12*10000 = 120000 = $1D4C0 (hex)
keeping the lower 16 bits = $D4C0 = 54464

clear as mud?

PlantBob
- 14th June 2008, 19:42
Is there anyway to get around this?

mackrackit
- 14th June 2008, 21:35
Where are you sending the data? If sending to a PC, send the 12 and send the 10000. Let the program on the PC handle it.

Or, look at DIV32 in the manual.

mister_e
- 14th June 2008, 22:51
or switch to a 18F, and use LONG variable type ;)