No builtin base conversion!
$&2%v2/;FL:vK2*;OS#
Try it online!
Pushy has two stacks, and this answer makes use of this extensively.
There are two parts two this program. First, $&2%v2/;F
, converts the number to its reverse binary representation:
\ Implicit: Input is an integer on main stack.
$ ; \ While i != 0:
&2%v \ Put i % 2 on auxiliary stack
2/ \ i = i // 2 (integer division)
F \ Swap stacks (so result is on main stack)
Given the example 10, the stacks would appear as following on each iteration:
1: [10]
2: []
1: [5]
2: [0]
1: [2]
2: [0, 1]
1: [1]
2: [0, 1, 0]
1: [0]
2: [0, 1, 0, 1]
We can see that after the final iteration, 0, 1, 0, 1
has been created on the second stack - the reverse binary digits of 10, 0b1010
.
The second part of the code, L:vK2*;OS#
, is taken from my previous answer which converts binary to decimal. Using the method decsribed and explained in that answer, it converts the binary digits on the stack into a base 10 integer, and prints the result.