Hey guys, for some odd reason I'm attempting to code an Arduino calculator.
I was doing pretty well I thought, until I hit this small problem. I need to figure out how to add integers onto each other, but not actually add them. For example:
This is what WOULD happen:
int var1 = 2 + 3
Then var1 would = 5
But, instead, I'd want var1 to = those numbers combined, so = 23.
Just change the "10" in Mike's example to 2, 8 or 16 (plus a bit of jiggery-pokery with A-F), and you've got yourself the beginnings of a useful programmer's calculator.
You might want to look up BCD (Binary Coded Decimal) math techniques used by the old 4-bit machines.
It's not as fast but with enough memory you can calculate to arbitrary numbers of digits with total precision.
"It's not as fast" there is a major understatement, btw.
For those who use M$ Windoze, the calculator can be switched to scientific mode and will do hex, dec, oct and bin.