[Question]
  [
Given an integer N perform the following steps: (using 9 as an example).
1. Receive input N. (`9`)
2. Convert N from base10 to base2. (`1001`)
3. Increase every bit by 1. (`2112`)
4. Treat the result as base3 and convert it back to base10. (`68`)
5. Return/Output the result.
---
## Input
May be received in any reasonable number format.  
You only need to handle cases where N > 0.
---
## Output
Either return as a number or string, or print to `stdout`.
---
## Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code in bytes wins.
* Default loopholes are forbidden.
---
## Test Cases
```
1 -> 2
2 -> 7
5 -> 23
9 -> 68
10 -> 70
20 -> 211
1235 -> 150623
93825 -> 114252161
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 31 bytes
```
f=lambda n:n and 3*f(n/2)+n%2+1
```
[Try it online!](https://tio.run/##FYxBCoMwFAXX9hRvEzT1l5ofAlVo75IioYI@RXTR06fpYhYzi9m@x2el5pyec1zeYwQHInKEv6aGd7UtjbYup3UHMRFOoIIg6AWuK1Jw6v/BPzQMl2rbJx6oTThxe8H0Zw2DhoIytDb/AA "Python 2 – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 23 bytes
```
f=x=>x&&x%2+1+3*f(x>>1)
```
[Try it online!](https://tio.run/##JcVBDkAwEADAu1f0QnYVUY60n/ACQWVFulKN9PcVcZk55me@F09XqB2vW0pWR21iUcS8k0r2pYVojMJk2QPpdhA0qvZLSsyEWNjdfG7NyTtQJSwQ/jaBp@DJ7dAjDukF "JavaScript (Node.js) – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 44 bytes
```
long n(long x){return x<1?0:x%2+1+3*n(x/2);}
```
[Try it online!](https://tio.run/##fY3LDoIwEEX3fMXExKS1irbERAXjD@jKpXFRBUkRCoGiGMK311ofC2Nc3UzuuWcSfuGjJDzrY8qrCjZcyNbRaS5jkMhGg9syUnUpoQnoarJo@oxQ4g0kasYM@512AIr6kIojVIorE5dchJAZE9qqUsh4t@e4NRRYPWSwBBld7YGwb4tTXj6/iSX1QQTUYyYIwbYF2N4qFWVuXiu3MEqFMlcigUlv2HsZvon04/7RPNaUedM1/s/MvRl7Q53T6Ts "Java (JDK 10) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
B‘ḅ3
```
[Try it online!](https://tio.run/##y0rNyan8/9/pUcOMhztajf///28JAA "Jelly – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 7 bytes
```
3#.1+#:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/jZX1DLWVrf5rcilwpSZn5CsopCkZKGTqGRlA@WkKhkbGpjC2pbGFkSnXfwA "J – Try It Online")
Thanks Galen Ivanov for -4 bytes! I really need to improve my J golfing skill...
[Answer]
# [R](https://www.r-project.org/), ~~55~~ 43 bytes
```
function(n)(n%/%2^(x=0:log2(n))%%2+1)%*%3^x
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPUyNPVV/VKE6jwtbAKic/3QgopKmqaqRtqKmqpWocV/E/TcPS2MLIVPM/AA "R – Try It Online")
Uses the standard base conversion trick in R, increments, and then uses a dot product with powers of `3` to convert back to an integer.
Thanks to [@user2390246](https://codegolf.stackexchange.com/users/66252/user2390246) for dropping 12 bytes!
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
b€>3β
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/6VHTGjvjc5v@/zcyAAA "05AB1E – Try It Online")
```
b       binary
 €>     increment each
   3β   base 3
```
---
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
2в>3β
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f6MImO@Nzm4AMAwA "05AB1E – Try It Online")
[Answer]
# Java 10, ~~81~~ 52 bytes (Base conversion)
```
n->n.toString(n,2).chars().reduce(0,(r,c)->r*3+c-47)
```
[Try it online.](https://tio.run/##hY7BTsMwDIbvfQprJ4e2EW2ZxlS2J9h22RFxCGk2srXOlKSbEOqzl7QFDggJKdEv279/fydxFempOveyFs7BVmj6iAA0eWUPQirYDSVAbegIEjeDECtDrws/vB0QrKCndE3cm723mo5ISc64fBPWIeNWVa1UeJ@gTSRL1/auiGX6sGB9GYWAS/taawnOCx/kanQFTaDAKer5RbCJYECDJtwidRsLHDEADsbiiKdXWQn6KSvyIHHMxinA/t151XDTen4JkR4bTlyiZvEsmX1l/PbUP@l/TKb9LC/mG/afa1k85t@2Lur6Tw)
-29 bytes thanks to *@Holger*.
**Explanation:**
```
n->{                         // Method with Long as both parameter and return-type
  n.toString(n,2)            //  Convert the input to a Base-2 String
  .chars().reduce(0,(r,c)->  //  Loop over its digits as bytes
    r*3+c-47)                //  Multiply the current result by 3, and add the digit + 1
                             //  (which is equal to increasing each digit by 1,
                             //  and then converting from Base-3 to Base-10)
```
---
# Java 10, ~~171~~ ~~167~~ ~~151~~ ~~150~~ 149 bytes (Sequence)
```
n->{int t=31-n.numberOfLeadingZeros(n);return a(t+1)+b(n-(1<<t));};int a(int n){return--n<1?n+2:3*a(n)+1;}int b(int n){return n<1?0:n+3*b(n/=2)+n*2;}
```
-16 bytes thanks to *@musicman523*, changing `(int)Math.pow(2,t)` to `(1<<t)`.  
-1 byte thanks to *@Holger*, changing `(int)(Math.log(n)/Math.log(2))` to `31-n.numberOfLeadingZeros(n)`.
[Try it online.](https://tio.run/##hY9RS8MwEMff@ymOPSWLraZF0KXVZ0Hnw94UH9IuG5nrdaTpREo/e710Q1AEIclxd7//5f47fdTxbv0@VnvdtvCkLfYRgEVv3EZXBpYhnQpQsQcqb40D5IqqA106S0AoYMT4rg@ULzIZY4JdXRr3vHk0em1x@2Jc0zLSOeM7h6CZF5KLkmHMZJ57ztWgglyz8CLvT2AcYy7vUaSLbK5JL6QaAlD@xCBQVwsU2ZxGXhYpFzhP1TCqiDY8dOXeVtB67SkcG7uGmoyylXe02uub5ieTwT3UZAbNx5SwySfApnHTf7aQCmwus5SCEHxqAqw@W2/qpOl8cqCJntUJJhWzXMwuZucRv5n99/A/Oie9TLNr/h90m92kZ2qIhvEL)
**Explanation:**
```
n->{                         // Method with Integer as both parameter and return-type
  int t=31-n.numberOfLeadingZeros(n);
                             //  2_log(n)
  return a(t+1)              //  Return A060816(2_log(n)+1)
         +b(n-(1<<t));}      //   + A005836(n-2^2_log(n))
// A060816: a(n) = 3*a(n-1) + 1; a(0)=1, a(1)=2
int a(int n){return--n<1?n+2:3*a(n)+1;}
// A005836: a(n+1) = 3*a(floor(n/2)) + n - 2*floor(n/2).
int b(int n){return n<1?0:n+3*b(n/=2)+n*2;}
```
When we look at the sequence:
```
2,  7,8,  22,23,25,26,  67,68,70,71,76,77,79,80,  202,203,205,206,211,212,214,215,229,230,232,233,238,239,241,242, ...
```
We can see multiple subsequences:
```
A053645(n):
0,  0,1,  0,1,2,3,  0,1,2,3,4,5,6,7,  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,  ...
A060816(A053645(n)):
2,  7,7,  22,22,22,22,  67,67,67,67,67,67,67,67,  202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,  ...
A005836(A053645(n)+1)
0,  0,1,  0,1,3,4,  0,1,3,4,9,10,12,13,  0,1,3,4,9,10,12,13,27,28,30,31,36,37,39,40,  ...
```
So the sequence being asked is:
```
A060816(A053645(n)) + A005836(A053645(n)+1)
```
---
I suck at finding patterns, so I'm proud of what I found above.. Having said that, *@user202729* found [a better and shorter approach in Java](https://codegolf.stackexchange.com/a/161625/52210) within a few minutes.. :'(
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 10 bytes
```
3⊥1+2⊥⍣¯1⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R2wTjR11LDbWNgOSj3sWH1hs@6loElFAw5EpTMAJiUyC2VAAShgYgEQMA "APL (Dyalog Unicode) – Try It Online")
```
    2⊥⍣¯1  binary
  1+       go guess
3⊥         base 3
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 7 bytes
```
ḃ+₁ᵐ~ḃ₃
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@GOZu1HTY0Pt06oAzIfNTX//29oZGz6PwoA "Brachylog – Try It Online")
### Explanation
Not that you really need one, but…
```
ḃ            To binary
 +₁ᵐ         Map increment
    ~ḃ₃      From ternary
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 27 bytes
```
f=->x{x>0?x%2+1+3*f[x/2]:0}
```
[Try it online!](https://tio.run/##NYtBCsIwFET3/xQBcWOtZiYmVsF4kJCFisGlSIVI27NHpHH3ePPm9b5@Skmn1uche33OSzZozCqFvGU86qkErBeq9YrCGfZiqzFymMl1Al1XLaxIQEBTa1jtfg/T8W@woyUcJG7ul9tjGPvxqVLo41S@ "Ruby – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~56~~ 55 bytes
```
lambda n:int(''.join('12'[c>'0']for c in bin(n)[2:]),3)
```
[Try it online!](https://tio.run/##TYxNDoIwEEb3nmISF20TYzpTW5FEL4IsANOI0SkhbDx9hRqLy/e@n@E93QNT9OdrfDav9tYAlz1PUoj9I/QsBZKouovQovZhhA56hnb2rCoqa7UzKg7jPAAvUcEWaPNDWvCY0abUZD4t7IrMqFNfr/skCHGtkEkvaLX7fzIFfT0eyBI6jB8 "Python 2 – Try It Online")
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/attache), 19 bytes
```
FromBase&3@1&`+@Bin
```
[Try it online!](https://tio.run/##SywpSUzOSP2fZmX7360oP9cpsThVzdjBUC1B28EpM@@/X2pqSnG0SkFBcnosV0BRZl5JSGpxiTNQVXF0mo5CtKGOkY6pjqWOoYGOkYGOoZExkGNsYWQaG/sfAA "Attache – Try It Online")
This is a composition of three functions:
* `FromBase&3`
* `1&`+`
* `Bin`
This first converts to binary (`Bin`), increments it (`1&`+`), then converts to ternary (`FromBase&3`).
## Alternatives
Non-pointfree, 21 bytes: `{FromBase[Bin!_+1,3]}`
Without builtins, 57 bytes: `Sum@{_*3^(#_-Iota!_-1)}@{If[_>0,$[_/2|Floor]'(1+_%2),[]]}`
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 36 bytes
```
.+
$*
+`^(1+)\1
$1;1
^
1
+`1;
;111
1
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRYtLOyFOw1BbM8aQS8XQ2pArjssQKGRozWVtaGjIZfj/vyUA "Retina 0.8.2 – Try It Online") Explanation:
```
.+
$*
```
Convert from decimal to unary.
```
+`^(1+)\1
$1;1
```
Repeatedly divmod by 2, and add 1 to the result of the modulo.
```
^
1
```
Add 1 to the first digit too.
```
+`1;
;111
```
Convert from unary-encoded base 3 to unary.
```
1
```
Convert to decimal.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 bytes
```
¤cÄ n3
¤      // Convert the input to a base-2 string,
 c     // then map over it as charcodes.
  Ä    // For each item, add one to its charcode
       // and when that's done,
    n3 // parse the string as a base 3 number.
 
```
Takes input as a number, outputs a number.
[Try it online!](https://tio.run/##y0osKPn//9CS5MMtCnnG//9bAgA "Japt – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~12~~ ~~7~~ 6 bytes
```
BQ3_ZA
```
[Try it online!](https://tio.run/##y00syfn/3ynQOD7K8f9/SwA "MATL – Try It Online")
Saved **5** bytes thanks to Giuseppe and another one thanks to Luis Mendo.
Old 7 byte answer: 
```
YBQc3ZA
```
[Try it online!](https://tio.run/##y00syfn/P9IpMNk4yvH/f0sA "MATL – Try It Online")
### Explanation:
```
YB        % Convert to binary string
  Q       % Increment each element
   c      % Convert ASCII values to characters
    3     % Push 3
     ZA   % Convert from base 3 to decimal.
```
---
Old one for 12 bytes:
```
BQtz:q3w^!Y*
```
[Try it online!](https://tio.run/##y00syfn/3ymwpMqq0Lg8TjFS6/9/SwA "MATL – Try It Online")
Oh my, that was messy... So is this: `BQ3GBn:q^!Y\*.
### Explanation:
```
               % Implicit input
B              % Convert to binary vector
 Q             % Increment all numbers
  t            % Duplicate
   z           % Number of element in vector
    :          % Range from 1 to that number
     q         % Decrement to get the range from 0 instead of 1
      3        % Push 3
       w       % Swap order of stack
        ^      % Raise 3 to the power of 0, 1, ...
         !     % Transpose
          Y*   % Matrix multiplication
               % Implicit output
```
[Answer]
# [C# (Visual C# Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 128 bytes
```
using System;using System.Linq;i=>{int z=0;return Convert.ToString(i,2).Reverse().Select(a=>(a-47)*(int)Math.Pow(3,z++)).Sum();}
```
[Try it online!](https://tio.run/##TZBBS8QwEIXPya@YY@J2w27rolLbi@DJhWIFD@IhxHQ3sE0wSVfc0t8ep1LQEMLM8N6bj6iwVkGlIRh7gPY7RN2X9H8nnoz9LCkNUUajQJ1kCNB4d/Cy70dKlvnZmQ/YS2NZiB7db@8g/SHwkVJYzuNg1b2xMQN8auiqZKp6xBou1ab0Og7ewoOzZ@2jeHHtbw4zWc7Fs8Zh0IyLVp@0ikxWNZPr6xt@xTCA72U8isZ9sSK7rFYcZUPPeDmlkhLSOa@lOi5gYIceARY6AEJQQmYKC9VMJho5r0IZn90EiYI7afHqTdT4GZp1zPI/QM5LmDMmineiKW1TnnbpLm03Kd@kbV5gU9zmux8 "C# (Visual C# Compiler) – Try It Online")
I am counting `System` because i use `Convert` and `Math`.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~56~~ 54 bytes
```
lambda i:int(''.join(`int(x)+1`for x in bin(i)[2:]),3)
```
[Try it online!](https://tio.run/##FcxBCoQwDEDRq2Rng2GwKcJMwZOoYEWKGbQVcaGnr@3yv8U/nmuNgZPvhrS5fV4ciJVwqar6/KMENZW4sdaTjyfcIAHmzII92xHJYCruiveamFr6kW6IG9Jscpgvt6M9zrwBrxymFw "Python 2 – Try It Online")
[Answer]
# C, ~~32~~ 27 bytes
```
n(x){x=x?x%2+1+3*n(x/2):0;}
```
Based on [user202729](https://codegolf.stackexchange.com/users/69850/user202729)'s Java [answer](https://codegolf.stackexchange.com/a/161625/79343). Try it online [here](https://tio.run/##S9ZNT07@/z9Po0KzusK2wr5C1UjbUNtYCyigb6RpZWBd@18hNzEzT0OzmksBCNLyizQy80oUMm0NrRUybQyNjYCUtrYmWFJBoaAIKJmmoaSaoqOkk6eRqalpDZYpKC0p1lBSgvHgqmLyQMoMjYxNNXHIWRpbGEEla7n@AwA).
Thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) for golfing 5 bytes.
Ungolfed version:
```
n(x) { // recursive function; both argument and return type are implicitly int
    x = // implicit return
    x ? x % 2 + 1 + 3*n(x/2) // if x != 0 return x % 2 + 1 + 3*n(x/2) (recursive call)
    : 0; // else return 0
}
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
B3m→ḋ
```
[Try it online!](https://tio.run/##yygtzv7/38k491HbpIc7uv///29pbGFkCgA "Husk – Try It Online")
### Explanation
```
B3m→ḋ
    ḋ  Convert to base 2
  m→   Map increment
B3     Convert from base 3
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/) with the communication toolbox, ~~33~~ 32 bytes
```
@(x)(de2bi(x)+1)*3.^(0:log2(x))'
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0JTIyXVKCkTyNA21NQy1ovTMLDKyU83Agpoqv9P0zDU5ErTMAIRpiDCEkQYGmj@BwA "Octave – Try It Online")
Converts the input to a binary vector using `de2bi`, and incrementing all numbers. Does matrix multiplication with a vertical vector of **3** raised to the appropriate powers: `1, 3, 9, ...`, thus getting the sum without an explicit call to `sum`.
[Answer]
## PHP, 84 64 Bytes
[Try it online!!](https://tio.run/##FcpBCoAgEEDRq7QQcshF0SosOoo0NlIQo5i1ic5utvnw4Ict5HEOpe5im3bPlZOC4RE4rWRx51@a7OYrXE4y1vNNMUmBzZmiiRRoSbLualV4UNkRQPWqa0G/2ckBdP4A)
**ORIGINAL Code**
```
function f($n){$b=decbin($n);echo base_convert($b+str_repeat('1',strlen($b)),3,10);}
```
[Try it online!!](https://tio.run/##K8go@G9jXwAk00rzkksy8/MU0jRU8jSrU5Mz8hWSEotT45Pz88pSi0o0ikuKSoo0UlKTkzLzQEp0DA10jAw1dYyBDE3r2v9pGpaa1v8B)
**Thanks to Cristoph**, less bytes if ran with php -R
```
function f($n){echo base_convert(strtr(decbin($n),10,21),3,10);}
```
**Explanation**
```
function f($n){
$b=decbin($n);                    #Convert the iteger to base 2
echo base_convert(                  #base conversion PHP function
    $b+str_repeat('1',strlen($b)),  #It adds to our base 2 number
    3,                              #a number of the same digits length
    10);                            #with purely '1's
}
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 8 bytes
```
ri2b:)3b
```
[Try it online!](https://tio.run/##S85KzP3/vyjTKMlK0zjp/39LYwsjUwA "CJam – Try It Online")
### Explanation
```
ri   e# Read input as an integer
2b   e# Convert to base 2. Gives a list containing 0 and 1
:)   e# Add 1 to each number in that list
3b   e# Convert list from base 3 to decimal. Implicitly display
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 28 bytes
```
f=->x{x>0?x%2+3*f[x>>1]+1:0}
```
black magic, no idea how it works
[Try it online!](https://tio.run/##KypNqvz/P81W166iusLOwL5C1UjbWCstusLOzjBW29DKoPZ/QWlJsUJadHpqSbFeSX58Zux/IwMA "Ruby – Try It Online")
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 117 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_number][T    T   T   _Retrieve][N
S S S N
_Create_Label_OUTER_LOOP][S N
S _Duplicate][S S S T   S N
_Push_2][T  S T T   _Modulo][S S S T    N
_Push_1][T  S S S _Add][S N
T   _Swap][S S S T  S N
_Push_2][T  S T S _Integer_division][S N
S _Duplicate][N
T   S N
_If_0_jump_to_Label_INNER_LOOP][N
S N
S N
_Jump_to_Label_OUTER_LOOP][N
S S N
_Create_Label_INNER_LOOP][S S S T   T   N
_Push_3][T  S S N
_Multiply][T    S S S _Add][S N
T   _Swap][S N
S _Duplicate][N
T   S T N
_If_0_jump_to_Label_PRINT_AND_EXIT][S N
T   _Swap][N
S N
N
_Jump_to_Label_INNER_LOOP][N
S S T   N
_Create_Label_PRINT_AND_EXIT][S N
T   _Swap][T    N
S T _Output_integer_to_STDOUT]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
[Try it online](https://tio.run/##PYtBCoBADAPPySvyBkXQ54gs6E1Q8Pm16aJtGUI7ffbjbte5bi1CErNzQLj4bSSIEOBEU8W@LSmjVdZ/Xkr71RJgWqF6TiBiGedhegE) (with raw spaces, tabs and new-lines only).
### Explanation in pseudo-code:
I first converted the recursive function `int f(int n){return n<1?0:n%2+1+3*f(n/2);}` to its iterative form (in pseudo-code):
```
Integer n = STDIN as integer
Add starting_value 0 to the stack
function OUTER_LOOP:
  while(true){
    Add n%2+1 to the stack
    n = n/2
    if(n == 0):
      Jump to INNER_LOOP
    Else:
      Jump to next iteration OUTER_LOOP
function INNER_LOOP:
  while(true){
    n = 3*n
    n = n + Value at the top of the stack (the ones we calculated with n%2+1)
    Swap top two items
    Check if the top is now 0 (starting value):
      Jump to PRINT_AND_EXIT
    Else:
      Swap top two items back
      Jump to next iteration INNER_LOOP
function PRINT_AND_EXIT:
  Swap top two items back
  Print top to STDOUT as integer
  Exit program with error: Exit not defined
```
And I then implemented this iterative approach in the stack-based language Whitespace, using it's default stack.
### Example runs:
**Input: `1`**
```
Command    Explanation                   Stack           Heap    STDIN   STDOUT   STDERR
SSSN       Push 0                        [0]
SNS        Duplicate top (0)             [0,0]
SNS        Duplicate top (0)             [0,0,0]
TNTT       Read STDIN as integer         [0,0]           {0:1}   1
TTT        Retrieve                      [0,1]           {0:1}
NSSSN      Create Label OUTER_LOOP       [0,1]           {0:1}
 SNS       Duplicate top (1)             [0,1,1]         {0:1}
 SSSTSN    Push 2                        [0,1,1,2]       {0:1}
 TSTT      Modulo top two (1%2)          [0,1,1]         {0:1}
 SSSTN     Push 1                        [0,1,1,1]       {0:1}
 TSSS      Add top two (1+1)             [0,1,2]         {0:1}
 SNT       Swap top two                  [0,2,1]         {0:1}
 SSSTSN    Push 2                        [0,2,1,2]       {0:1}
 TSTS      Int-divide top two (1/2)      [0,2,0]         {0:1}
 SNS       Duplicate top (0)             [0,2,0,0]       {0:1}
 NTSN      If 0: Go to Label INNER_LOOP  [0,2,0]         {0:1}
 NSSN      Create Label INNER_LOOP       [0,2,0]         {0:1}
  SSSTTN   Push 3                        [0,2,0,3]       {0:1}
  TSSN     Multiply top two (0*3)        [0,2,0]         {0:1}
  TSSS     Add top two (2+0)             [0,2]           {0:1}
  SNT      Swap top two                  [2,0]           {0:1}
  SNS      Duplicate top (0)             [2,0,0]         {0:1}
  NTSTN    If 0: Jump to Label PRINT     [2,0]           {0:1}
  NSSTN    Create Label PRINT            [2,0]           {0:1}
   SNT     Swap top two                  [0,2]           {0:1}
   TNST    Print top to STDOUT           [0]             {0:1}           2
                                                                                  error
```
[Try it online](https://tio.run/##PYtBCoBADAPPySvyBZ8ksqA3QcHn16SLtmUI7fTZj3tc57qNKkl0e0Ck@G0kiBCQxFDNuW3JMSr735fWfrUFhFGomQ1ULS8) (with raw spaces, tabs and new-lines only).  
Stops with error: Exit not defined.
**Input: `4`**
```
Command    Explanation                   Stack           Heap    STDIN   STDOUT   STDERR
SSSN       Push 0                        [0]
SNS        Duplicate top (0)             [0,0]
SNS        Duplicate top (0)             [0,0,0]
TNTT       Read STDIN as integer         [0,0]           {0:4}   4
TTT        Retrieve                      [0,4]           {0:4}
NSSSN      Create Label OUTER_LOOP       [0,4]           {0:4}
 SNS       Duplicate top (4)             [0,4,4]         {0:4}
 SSSTSN    Push 2                        [0,4,4,2]       {0:4}
 TSTT      Modulo top two (4%2)          [0,4,0]         {0:4}
 SSSTN     Push 1                        [0,4,0,1]       {0:4}
 TSSS      Add top two (0+1)             [0,4,1]         {0:4}
 SNT       Swap top two                  [0,1,4]         {0:4}
 SSSTSN    Push 2                        [0,1,4,2]       {0:4}
 TSTS      Int-divide top two (4/2)      [0,1,2]         {0:4}
 SNS       Duplicate top (2)             [0,1,2,2]       {0:4}
 NTSN      If 0: Go to Label INNER_LOOP  [0,1,2]         {0:4}
 NSNSN     Jump to Label OUTER_LOOP      [0,1,2]         {0:4}
 SNS       Duplicate top (2)             [0,1,2,2]       {0:4}
 SSSTSN    Push 2                        [0,1,2,2,2]     {0:4}
 TSTT      Modulo top two (2%2)          [0,1,2,0]       {0:4}
 SSSTN     Push 1                        [0,1,2,0,1]     {0:4}
 TSSS      Add top two (0+1)             [0,1,2,1]       {0:4}
 SNT       Swap top two                  [0,1,1,2]       {0:4}
 SSSTSN    Push 2                        [0,1,1,2,2]     {0:4}
 TSTS      Int-divide top two (2/2)      [0,1,1,1]       {0:4}
 SNS       Duplicate top (1)             [0,1,1,1,1]     {0:4}
 NTSN      If 0: Go to Label INNER_LOOP  [0,1,1,1]       {0:4}
 NSNSN     Jump to Label OUTER_LOOP      [0,1,1,1]       {0:4}
 SNS       Duplicate top (1)             [0,1,1,1,1]     {0:4}
 SSSTSN    Push 2                        [0,1,1,1,1,2]   {0:4}
 TSTT      Modulo top two (1%2)          [0,1,1,1,1]     {0:4}
 SSSTN     Push 1                        [0,1,1,1,1,1]   {0:4}
 TSSS      Add top two (1+1)             [0,1,1,1,2]     {0:4}
 SNT       Swap top two                  [0,1,1,2,1]     {0:4}
 SSSTSN    Push 2                        [0,1,1,2,1,2]   {0:4}
 TSTS      Int-divide top two (1/2)      [0,1,1,2,0]     {0:4}
 SNS       Duplicate top (0)             [0,1,1,2,0,0]   {0:4}
 NTSN      If 0: Go to Label INNER_LOOP  [0,1,1,2,0]     {0:4}
 NSSN      Create Label INNER_LOOP       [0,1,1,2,0]     {0:4}
  SSSTTN   Push 3                        [0,1,1,2,0,3]   {0:4}
  TSSN     Multiply top two (0*3)        [0,1,1,2,0]     {0:4}
  TSSS     Add top two (2+0)             [0,1,1,2]       {0:4}
  SNT      Swap top two                  [0,1,2,1]       {0:4}
  SNS      Duplicate top (1)             [0,1,2,1,1]     {0:4}
  NTSTN    If 0: Jump to Label PRINT     [0,1,2,1]       {0:4}
  SNT      Swap top two                  [0,1,1,2]       {0:4}
  NSNN     Jump to Label INNER_LOOP      [0,1,1,2]       {0:4}
  SSSTTN   Push 3                        [0,1,1,2,3]     {0:4}
  TSSN     Multiply top two (2*3)        [0,1,1,6]       {0:4}
  TSSS     Add top two (1+6)             [0,1,7]         {0:4}
  SNT      Swap top two                  [0,7,1]         {0:4}
  SNS      Duplicate top (1)             [0,7,1,1]       {0:4}
  NTSTN    If 0: Jump to Label PRINT     [0,7,1]         {0:4}
  SNT      Swap top two                  [0,1,7]         {0:4}
  NSNN     Jump to Label INNER_LOOP      [0,1,7]         {0:4}
  SSSTTN   Push 3                        [0,1,7,3]       {0:4}
  TSSN     Multiply top two (7*3)        [0,1,21]        {0:4}
  TSSS     Add top two (1+21)            [0,22]          {0:4}
  SNT      Swap top two                  [22,0]          {0:4}
  SNS      Duplicate top (0)             [22,0,0]        {0:4}
  NTSTN    If 0: Jump to Label PRINT     [22,0]          {0:4}
  NSSTN    Create Label PRINT            [22,0]          {0:4}
   SNT     Swap top two                  [0,22]          {0:4}
   TNST    Print top to STDOUT           [0]             {0:4}           22
                                                                                  error
```
[Try it online](https://tio.run/##PYtBCoBADAPPySvyCD8ksqA3QcHn16SLtmUI7fTZj3tc57qNKkl0e0Ck@G0kiBCQxFDNuW3JMSr735fWfrUFhFGomQ1ULS8) (with raw spaces, tabs and new-lines only).  
Stops with error: Exit not defined.
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 74 bytes
```
({<>(())<>({<({}[()])><>([{}]())<>})}(<>)){{}((({})()){}{}[{}])([][()])}{}
```
[Try it online!](https://tio.run/##HYsxCoBAEAO/kxQWKnbHfeS44iwEUSxsw759DTaBGSb7O85nOu5xZUKlAqRXBYoGdlZTU/TfBwOlklIALmircOmAaP1/mDPnZd0@ "Brain-Flak – Try It Online")
## "Readable" version
```
({<>(())<>
  ({
    <({}[()])>
    <>
    ([{}]())
    <>
  })
}
# At this point we have a inverted binary string on the stack
(<>)
)
{
  {}
  (
    (({})()){}{}[{}]
  )
  ([][()])
}{}
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
b›3β
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=b%E2%80%BA3%CE%B2&inputs=9&header=&footer=)
```
b    # Binary
 ›   # Increment
  3β # From base 3
```
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 14 bytes
```
L,BBu1€+B]3$Bb
```
[Try it online!](https://tio.run/##S0xJKSj4/99Hx8mp1PBR0xptp1hjFaek////W/7LLyjJzM8r/q@rm5lbkJOZnFkCAA "Add++ – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 7 bytes
```
¤£°XÃn3
```
[Try it here](https://ethproductions.github.io/japt/?v=1.4.5&code=pKOwWMNuMw==&input=OA==)
[Answer]
# [Haskell](https://www.haskell.org/), 32 bytes
```
f 0=0
f a=1+mod a 2+3*f(div a 2)
```
[Try it online!](https://tio.run/##FcdNDkAwEAbQvVN8Sz8TaaeRsOgRnEBEJqHRUARx/WL33izXMq1rjA7KqsRBrC7CPkLAhcldOvrndxaD@A0WQY52QHqcfrtRwmXoNDFV1JBWxIo0my@m5qqPLw "Haskell – Try It Online")
]