"Concatenating" integers?

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.

2 + 8 would = 28 etc etc etc

Is there a way to do this?


Sort of like this?

// input var1
varTotal = (varTotal * 10) + var1;
// have we finished? if not go back to input an other number

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.

Works well, except the integers are in the wrong order.

eg: 123

Comes out as 321.

Thanks for the help.

Works well, except the integers are in the wrong order

You must've entered them in the wrong order.

Derp, stupid error haha. Thanks for the help :slight_smile:

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.

Scientific Mode also includes some Programmer stuff, like Hex/Octal/Binary modes, and Quad-Word, Doouble-Word, Word (INT), Byte

Layed out differently yet again in Vista I've noticed.