Befunge - 2x11 = 22 characters
So close, Befunge will win one day.
The biggest distinguishing feature of Befunge is that instead of being a linear set of instructions like most languages; it is a 2d grid of single character instructions, where control can flow in any direction.
These characters change the direction of control when they are hit, this makes the main loop.
This inputs a number and pushes it onto the stack (
&), pops the top two values off the stack, adds them and pushes them back onto the stack (
+), inputs a single character and places its ascii value on the stack (
~), then pushes 1 onto the stack and adds them (
The interpreter I've been using returns -1 for end of input, some return 0 instead so the
1+ part could be removed for them.
# causes the next character to be skipped, then the
_ pops a value off the stack and if it is zero sends control right, otherwise sends it left. If the value was zero
. pops a value off the stack and outputs it as an integer and
@ stops the program. Otherwise
v sends control down to the return loop.
This simply multiplies the top value of the stack by 256 and returns control to the start.