text:
Transpile WordMath
We've all seen those online "maths hax" that look like this:
Think of a number, divide by 2, multiply by 0, add 8.

And, by magic, everyone ends up with the number 8!

Language
Let's define a programming language which uses the syntax of the text above, called "WordMath". WordMath scripts follow this template:
Think of a number, <commandlist>.

Which basically means: Take a number (as input from STDIN) as the initial accumulator, perform all commands on it, and output the result.
The commands are seperated by the delimiter , (comma + space). The valid commands are (note that # represents a non-negative integer:):

add # / subtract # - Add/subtract the value from the accumulator.
divide by # / multiply by # - floordiv / multiply the accumulator by the given value.
subtract from # - Similar to subtract, but does acc = # - acc instead of acc = acc - #
repeat - do last command again. This cannot be the 1st command, but you must support multiple consecutive repeats.

The Challenge
Your task is to create a program or function which takes a valid WordMath script as input and
transpiles it into a valid full program - in the same language your code is in.
For example, if my code is in Python 2 and the script is:
Think of a number, subtract from 10, add 10, multiply by 2.

The outputted program can be:
a = input()
a = 10 - a
a += 10
a *= 2
print(a)

Or alternatively:
print(((10-input())+10)*2)

As long as it is a full program which takes input from STDIN and prints to STDOUT, or the language's nearest equivalents.

Rules

Your original program may assume that the input is always a valid WordMath script.
The transpiled programs do not have to handle mathematical errors such as division by 0.
The transpiled programs may assume that the input represents a valid signed integer, within your language's standard integer range.
This is code-golf, so the shortest solution (in bytes) wins.
Only the byte count of your original program matters - the outputted code can be as long as you want!

Example Scripts
Example 1:
Think of a number.

Take input, do nothing, display it: WordMath's cat program.
Example 2:
Think of a number, divide by 5, subtract from 9.

Remember that "divide" is floor division, so for this program 6 -> 8, and 29 -> 4.
Example 3:
Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2.

The extended cat program!
Example 4:
Think of a number, subtract 1, repeat, repeat.

Takes a number and subtracts 3.

Do we have to support consecutive repeats?

Can we use floats when that's the language's default type / if it doesn't support integers?

@RainerP. only if the language doesn't support integers/integer division

@darrylyeo yes, I'll make that clear in the spec.

You might want a test case with repeat at the end, and more than one repeat in a row.

@mbomb007 yeah, I'll do that now.

What is the expected result of -5/3? Do we round towards 0 or towards negative infinity?

@MartinEnder I'd say round towards negative infinity as it's floor division, but if your language implements integer division towards 0 that's fine too.

The order of multiply and divide should be switched. I know that it's clear what you're saying.

05AB1E, 59 56 54 52 bytes
„, ¡¦vyDþs.AJá'bK"dmas""/*+-"‡„-f„s-.:«D'rQi®}©}J'rK

Try it online!
My brain hurts like hell after that... It outputs in 05AB1E code as follows:

Think of a Number is removed, due to implicit input.
Subtract From # coverts to #s- (swap a and b and perform operation).
Subtract # converts to #-.
Add # converts to #+.
Multiply by # converts to #*.
Divide by # converts to #/.
Repeat grabs whatever was last stored in the register and concatenates it.

Explained:
„, ¡                                                 # Split on ', '.
    ¦                                                # Remove the 'Think of a number'.
     vy                                        }     # Loop through chunks.
       Dþs                                           # Dupe, push only digits, swap.
          .AJá                                       # Acronymify without digits.
              'bK                                    # Remove the `b`.
                 "dmas""/*+-"‡                       # Replace letters with OPs.
                              „-f„s-.:               # Replace '-f' with 's-'.
                                      «              # Concat # with OP.
                                       D'rQ          # Dupe, push 1 if OP='r'.
                                           i®}       # If 'r', push last #OP.
                                              ©      # Store current OP.
                                                J'rK # Join, remove remaining r's.

Example:
Input:
Think of a number, divide by 2, multiply by 10, add 8, subtract 6, subtract from 9, repeat, repeat, subtract 41.

Output:
2/10*8+6-9s-9s-9s-41-

Try solution with input of 10:
Try it online!
See it on google:
Here's a link to the same equation typed into google.

C Preprocessor, 362 Bytes
I ALMOST got this working in JUST the C preprocessor, but the repeat command turns out to be far too difficult to implement. So instead I used the preprocessor to turn the input into an array that is then interpreted by some additional code.
main(){int c[]={
#define Think
#define of
#define a
#define number 0
#define add 1,
#define subtract 2,
#define from 0,3,
#define multiply 4,
#define divide 5,
#define by
#define repeat 6, 0
#include "input.wm"
,'$'};int _,l,v;scanf("%d", &_);for(int i=1;c[i]-'$';++i){c[i]!=6?l=c[i],v=c[++i]:++i;l==1?_+=v:l==2?_-=v:l==3?_=v-_:l==4?_*=v:_/=v;}printf("%d",_);}

The input must be provided in "input.wm" or just dumped in the source at that line. I included its bytes in my count because I figure its a bit hacky and slightly against the rules of the challenge, so it is only fitting.
Anyways, once you dump your WordMath source into input.wm where a compiler can find it, you should be able to just compile this, as is, with warnings to produce an executable that does what the WordMath source says.

Note: this unfortunately fails with some compilers when you end with repeat. This is because they toss a space after the 0 and then see a stray period and don't know what to do with it.

clever, i'm impressed.

Retina, 170 bytes
Because who wouldn't want to see this?!
I thought of how awesome it'd be to see a Retina solution, and I decided to create it quick. It only took an hour. As usual, byte count assumes ISO 8859-1 encoding.
S`,
\.

T.*
.*¶$$*
\;+`(.*)¶rep.*(¶?)
$1¶$1$2
\d+
$*
.*f.* (1*)
1¶x¶$¶$1¶+`x1¶
m.*
1¶
di.* (1*)
^¶$1 ¶^(1+) (\1)+1*$¶x$$#+¶1+ 1*¶x0¶x\d+¶$$*
s.* (1*)
^$1¶
a.*
^¶
\z
¶1

Try it online
Output has a trailing newline that should not be copied when testing the resulting program. The program does not support negatives, because Retina's standard integer range (in unary) does not.
Explanation:
S`,                 # Split input on ", " putting each command on its own line
\.                  # Remove the period

T.*                 # Think of a number -> .*\n$* (replaces input with unary)
.*¶$$*
\;+`(.*)¶rep.*(¶?)  # Loop, replacing "repeat" with the line before it
$1¶$1$2
\d+                 # Replace all numbers with their unary representation
$*
.*f.* (1*)          # Replace "subtract from " with a subtract from program
1¶x¶$¶$1¶+`x1¶
m.*                 # Replace "multiply by " with a multiply program
1¶
di.* (1*)           # Replace "divide by " by my integer division program
^¶$1 ¶^(1+) (\1)+1*$¶x$$#+¶1+ 1*¶x0¶x\d+¶$$*
s.* (1*)            # Replace "subtract " with a subtraction program
^$1¶
a.*                 # Replace "add " with an addition program
^¶
\z                  # At the end, add a stage to change unary into decimal
¶1

Math programs:
Add:
Add the number of ones to the beginning. Add 5:
^
1111

Subtract:
Remove the number of ones from the beginning. Subtract 5:
^11111

Subtract from:
Replace input 1s with xs. Put next to the fixed number. Repeatedly remove x1. Subtract from 10:
1
x
$
1111111111
+`x1

Multiply by:
Replace every 1 with a certain number of them. Multiply by 3:
1
111

Divide by:
This uses my Retina program for Integer Division. Divide by 2:
^                   # Place the fixed divisor before the dividend
11
^(.+) (\1)+.*$      # Match the divisor, followed by each occurrence in the dividend.
x$#+                # Replace with the number of matches. Trailing ones are dropped
.+ .*               # If there are still two numbers, the result is zero
x0
x\d+                # Replace result (marked with an 'x') with unary
$*

I'm afraid I don't see how this can work. Whatever inputs I try for the subtraction commands, I get broken results (are there linefeeds missing in the output?). I also don't see how this handles negative inputs or negative intermediate results.

@MartinEnder I can fix subtraction if you explain why this simplified program gives two ones in the output. http://retina.tryitonline.net/#code=JArCtjE&input=dGVzdAo

Because $ matches at the very end of the string or in front of a trailing linefeed. You need \z if you only want the former.

Python 2, 263 258 260 221 bytes
This could probably still be much shorter.
def r(s,o="",p=""):c=s.pop(0);c=[c,p]['re'in c];n=c.split()[-1];o=[[o+[['+-'['s'in c],'//']['v'in c],'*']['m'in c]+n,n+'-'+o]['f'in c],'input()']['T'in c];return s and r(s,"(%s)"%o,c)or o
lambda s:"print "+r(s.split(','))

Try it online
I use // instead of /, because the last instruction will have a . at the end, making any number a float. So in order to keep division consistent, I use integer division.
Test cases output:
print input()
print 9.-((input())//5)
print ((((((input())+5)+10)+10)-15)-15)//2.
print (((input())-1)-1)-1

If you change that big block of ifs for o to the following (which I think should work): o=[[o+[['+-'['s'in c],'//']['v'in c],'*']['m'in c]+n,n+'-'+o]['f'in c],'input()']['T'in c], you can get it down to 224.

@Kade Yeah, it was still legible. Can't have that.

@Cyoce No, the very act of calling the lambda would probably cost more than it saves. It'd have to save 4 or 5 bytes per call to pay off.

Haskell, 232 231 bytes
Of course a functional programmer would prefer to return a function rather than a string representing a program, but here we go:
t l="main=getLine>>=print."++""%words l++"(0+).read"
x%((o:_):f:n:r)|o=='m'=h"*"n r|o=='d'=h"`div`"n r|f=="from"=h"(-)"n r
x%(s:n:r)|s=="add"=h"+"n r|s!!0=='s'=h s(' ':n)r
x%(_:r)=x%r++x
_%_=""
h s n r|x<-'(':s++init n++")."=x%r++x

Remarks: We always start with adding zero, otherwise the transpilation of the trivial WordMath program wouldn't give enough information to infer the type at which read is used. subtract from n could be implemented as (n-), but I use ((-)n) for more uniformity. In the case of subtract n I copy the subtract from the input so I don't have to write it, but I need to compensate for the missing space at the end. repeat is used as default operation; together with an empty initial previous operation this allows for easy ignoring of the first four words.
Usage example:
*Main> t "Think of a number. "
"main=getLine>>=print.(0+).read"

The other examples give the following results:
"main=getLine>>=print.((-)9).(`div`5).(0+).read"
"main=getLine>>=print.(`div`2).(subtract 15).(subtract 15).(*2).(+10).(+5).(0+).read"
"main=getLine>>=print.(subtract 1).(subtract 1).(subtract 1).(0+).read"

Just curious, how would you generate a function to return instead of a string?

In a functional programming language, creating and composing a function is no more difficult than creating and appending a string. h might look something like h s n r|x<-s.read.init$n=x%r.x and be called with first argument a function like h(+)n r (and there need to be some flip somewhere to get the correct operator order), base case is _%_=id. Main function can avoid all the boilerplate and just be t l=id%words l. - Thanks to currying, it might be seen as an interpreter, and that idea might lead to an easier and/or shorter solution.

Befunge, 342 305 bytes
>~$1 +:89+`#v_801p
  v_^#`+85~$<
1+>~:5+88+/3-!#v_$
v`"/":~p8p10+1<>>:"/"`!|
 "+"\5+8p4+:1+^:p11:g10<  >:"+"\2+8p:"*"\3+8p:
_$7%:01g\!#v_\2-7g\:1+:01v^p8+1\"5":p8\"5":g10
#8\"\"$#:0#<^v<p8p8\<g80p<>\#+$#12#p
-/+* >:#,_@  #^p8g10<
".@"<^"&"
10<v0<\g8-\g11:<:p1>#1+g11:p10+g
-:^>1g\-8p1-::#^_$8g^  >$$01g11g

Try it online!
Output
The code it generates starts with a & (input value) command, and finishes with . (output value) and @ (exit) commands. In between we have the various calculations in the form <number><operation>, where the operation can be + (add), - (subtract), / (divide by), * (multiply by), and \- (subtract from).
The  number itself is a bit complicated, because Befunge only supports numeric literals in the range 0 to 9, so anything larger than that needs to be manually calculated. Since we are already reading the numbers in character by character, we simply build up the number as each digit is read, so for example, 123 becomes 155+*2+55+*3+, i.e. (((1 * 10) + 2) * 10) + 3.
Examples
Input:  Think of a number.
Output: &.@

Input:  Think of a number, divide by 5, subtract from 9.
Output: &5/9\-.@

Input:  Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2.
Output: &5+155+*0++2*155+*5+-155+*5+-2/.@

Input:  Think of a number, subtract 1, repeat, repeat.
Output: &1-1-1-.@

Explanation
Befunge doesn't have the ability to manipulate strings as such, so most of the parsing is handled by counting characters. We start just by skipping the first 18 characters, which gets us past the Think of a number phrase (plus either a comma or period). Then if the next character is some form of newline or EOF we go straight to the output routine, otherwise we continue looking for a command list.
To parse a command, we just keep counting characters until we reach a digit or separator. If it's a separator, it must have been the repeat command which we handle as a special case. If it's a digit we add it to our output buffer, and continue looking for more digits. Each time a digit is output, we prefix it with 55+* (to multiply the total so far by 10) and suffix it with + (to add it to the total). Once the digits are finished we add the command character.
As for how the command is determined, we take the count of characters up to the first digit modulo 7. For add this is 4 (including the following space), for subtract it's 2, for divide by it's 3, for multiply by it's 5, and for subtract from it's 0. The subtract from requires a little additional handling since it needs the \- command combo, but the others just use their value to lookup the appropriate command character in a table.
This process is repeated for each command, building up the output into a preconstructed string on line 8. Each time an additional command is added, we also add a closing quote to the string to make sure it's always properly terminated. Then when we eventually reach the end of our input, we simply "execute" this string to push it onto the stack, then follow that with a standard output sequence to write it all out.

GNU awk, 139 bytes
BEGIN{RS="[,.]";c="{}{";ORS=";"}
/ad/{c="+="$2}
/c/{c="-="$2}
/om/{c="="$3"-$0"}
/l/{c="*="$3}
/v/{c="=int($0/"$3")"}
!NF{c="}1"}
$0="$0"c

Invocation:
$> awk `awk -f wordmath <<< "Think of a number, add 1, repeat, repeat."` <<< 0
$> 3

Test cases:
$> awk -f wordmath <<< "Think of a number."
$> $0{}{;$0}1;

$> awk -f wordmath <<< "Think of a number, divide by 5, subtract from 9."
$> $0{}{;$0=int($0/5);$0=9-$0;$0}1;

$> awk -f wordmath <<< "Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2."
$> $0{}{;$0+=5;$0+=10;$0*=2;$0-=15;$0-=15;$0=int($0/2);$0}1;

JavaScript (ES6), 163 bytes
w=>w.split`, `.map(l=>(o={a:'+',s:'-',m:'*',d:'/'}[a=l[0]])?p=(x=l.split` `.pop(),l[9]=='f'?x+`-n`:`n`+o+x+`|0`):a<'r'?'n=+prompt()':p).join`
n=`+`
console.log(n)`

Try it:

f=w=>w.split`, `.map(l=>(o={a:'+',s:'-',m:'*',d:'/'}[a=l[0]])?p=(x=l.split` `.pop(),l[9]=='f'?x+`-n`:`n`+o+x+`|0`):a<'r'?'n=+prompt()':p).join`
n=`+`
console.log(n)`

const program = f('Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2.')
document.write('<pre>' + program + '</pre>' )

eval(program)

/*
Outputs:

n=+prompt()
n=n+5|0
n=n+10|0
n=n*2|0
n=n-15|0
n=n-15|0
n=n/2.|0
console.log(n)
*/

Vim 208 171 168 bytes
Added the ability to do multiple repeats in a row as per @Flp.Tkc but golfed off enough bytes that I could still lower the byte count.
:map s :s;\v
c4wcw="s, s\w* \w+ (\d+); *-1+\1);g
s, ([adms]).{-}(\d+); \1\2);g
qws(\S+), r\w+;\1 \1
@wq@ws.*;\=tr(submatch(0),'adms','+/*-')
qq])T=i(@qq@qx$xA

TryItOnline
Unprintable characters:
:map s :s;\v
c4wcw^V^R=^V^R"^[s, s\w* \w+ (\d+); *-1+\1);g
s, ([adms]).{-}(\d+); \1\2);g
qws(\S+), r\w+;\1 \1
@wq@ws.*;\=tr(submatch(0),'adms','+/*-')
qq])T=i(^[@qq@qx$xA
^V^[^[

Test cases output:

cw^R=^R"
^[ TryItOnline
cw^R=((^R" /5) *-1+9)
^[ TryItOnline
cw^R=((((((^R" +5) +10) *2) -15) -15) /2)
^[ TryItOnline

This doesn't seem to work for multiple consecutive repeats.

@Flp.Tkc fixed, thank you!  I didn't notice that earlier.

Pyth, 69 67 bytes
J\QVtcQ\,Iq@N1\r=NZ)=Jjd+@"+-/*"x"asdm"@N1.>,J-ecN)\.qh@cN)1\f=ZN)J

A program that takes input of a "quoted string" and prints the result.
Test suite
How it works
Pyth has prefix operators, so the basic arithmetical operations are performed using (operator)(operand1)(operand2), while the pre-initialised variable Q gives the input. Hence, a transpiled WordMath program is constructed by starting with the string 'Q', and at each stage, prepending the operator, and then prepending or appending the operand as neccessary.
J\Q Set J, the transpiled program string, to the string 'Q'
tcQ\,  Split the input on commas, and discard the first element (which is 'Think of a number')
V  For N in that:

Iq@N1\r  If the character at N[1] is 'r' (repeat):

=NZ Set Nto Z (previous value of N, set at end of for loop)

x"asdm"@N1  Find the index of N[1] in "asdm" (add, subtract, divide, multiply)
@"+-/*"  Index with that into "+-/*", giving the required operator
,J-eCN)\. Yield the two-element list [J, -eCN)\.], where the second element is the last element of N split on whitespace with any '.' characters removed (operand)
qh@cN)1\f  If the first character of the second element of N split on whitespace is 'f' (subtract from):

.>  Swap the elements of the two-element list

+ Merge the operator and two-element list into one list
=Jjd  Set J to that joined on spaces
=ZN  Set Z to N

J  Print J

Nice answer man... Inspired me to try in 05AB1E, which... Was more intimidating than anticipated.

lex, 246 bytes
%{
#define P printf
#define O P("n%s%d;",c,v);
int v;char*c;
%}
%%
T {P("%%%%\n.* {int n=atoi(yytext);");}
ad {c="+=";}
fr {c="=-n+";}
s {c="-=";}
v {c="/=";}
l {c="*=";}
re {O}
[0-9]+ {v=atoi(yytext);O}
\. P("printf(\"%%d\",n);}\n%%%%");
. ;
%%

lex targets to C, so a C compiler would need to compile it into something executable.  The lexer library (ll) would also need to be linked.  This may add a byte-penalty, but I'm not sure how many bytes if so.
The program outputs a lex program (per specification) that evaluates the transpiled wordmath expression.  The code between %{ and %} is for the "transpiler" only:
#define P printf              /* for brevity */
#define O P("n%s%d;",c,v)     /* expression builder, calls P = printf */
int v;char*c;                 /* v=most recent integer read */
                              /* c=the expression infix */

Between the two %% lines is the regex/action portion.  The first rule to be matched would be T ("Think...") which builds the preamble (lex programs must start contain the rule section at the least, and yytext is last matching text, so the rule essentially seeds the accumulator with the user's input).
The program discards all input except for that which is matched, and the other rules (ad, fr, up to re) handle the wordmath expression clauses with as minimal a match as possible to be unique.  In most of these, it sets c to an expression infix, which gets concatenated between n and the last integer read when O gets called (so for example, reading "add 9" will set the infix to +=, v to 9, and the call to O will output n+=9;).  (An interesting aside is that "subtract from 8" will cause both the s and the fr rules to get matched, but since O is called only at the number, the proper rule n=-n+8; is the only expression that gets output).  The re rule for "repeat" just calls O again, which outputs the last created expression (and since subsequent matches will clobber yytext, supporting "repeat" is why the integer conversion in the [0-9]+ rule was required).  Finally, a period causes the program trailer to be output, which just outputs the accumulator and closes with the %% pair denoting the end of the output lex program.
Note:  Neither the main transpiler program or the output program will terminate.  Piping input in would work, or providing EOF (ctrl-D).  If termination is required after the first input, exit()s can be added.
To build/run:
Build the main program:
% lex -o wordmath.yy.c wordmath.l
% cc -o wordmath wordmath.yy.c -ll

Execute to create a specific transpiled program:
% echo "This is a number, add 8, subtract 5, repeat." | ./wordmath > program.l

Build the transpiled program:
% lex -o program.yy.c program.l
% cc -o program program.yy.c -ll

Execute the transpiled program (with input 3, called via a pipe or inline):
% echo 3 | ./program
1
% ./program
3
1
^D
%

Test 1:
%%
.* {int n=atoi(yytext);printf("%d",n);}
%%

Test 2:
%%
.* {int n=atoi(yytext);n/=5;n=-n+9;printf("%d",n);}
%%

Test 3:
%%
.* {int n=atoi(yytext);n+=5;n+=10;n*=2;n-=15;n-=15;n/=2;printf("%d",n);}
%%

Test 4:
%%
.* {int n=atoi(yytext);n-=1;n-=1;n-=1;printf("%d",n);}
%%

Pip, 58 bytes
Too bad I haven't implemented that reverse-subtraction operator yet.
{p:a:sNa?ap['Y("-y+  y- y// y+ y* "^sa@?Y`\d`)|'qa@y]}Mq^k

The program takes a WordMath script from stdin and outputs Pip code to stdout. The code that is output, similarly, takes a number from stdin and outputs the result to stdout. Try it online!
Strategy
For input like this:
Think of a number, multiply by 3, add 1.

we want output like this:
YqYy*3Yy+1

which works as follows:
Yq    Yank a line of stdin into y
Yy*3  Compute y*3 and yank result into y
Yy+1  Compute y+1 and yank result into y
      Last expression is autoprinted

Ungolfed + explanation
{
 p : a : sNa ? a p
 [
  'Y
  ("-y+  y- y// y+ y* "^s a@?Y`\d`) | 'q
  a@y
 ]
} M q^k

The basic structure of the program is {...}Mq^k, which splits q (a line of stdin) on k (comma-space) and Maps a function to each element.
Inside the function, we start by handling the repeat case. The shortest test in Pip seems to be sNa (is there a space in the command). If so, we want to use a; if not, use p, which stores the previous command. Assign that value back to a and also to p (for next time).
For our return value, we use a list, which is fine because the default output format for lists is to concatenate everything together. The result always starts with Y. Next, we need a lookup table for the operations.
Observe that the lengths of add  (4), subtract  (9), divide by  (10), multiply by  (12), and subtract from  (14) are all distinct. Further observe that they are still distinct when taken mod 7. Thus, we can use them to index into a seven-element list (containing five code snippets and two placeholders) to map each WordMath command to the appropriate Pip code (designed so the number can simply be concatenated to the end):

0: -y+ (subtract from)
1: placeholder
2: y- (subtract)
3: y// (divide by)
4: y+ (add)
5: y* (multiply by)
6: placeholder

For the indices, we use regex to get the index of the first digit in the command: a@?`\d`. We also yank the regex into y for future use. The lookup table is generated by splitting the string "-y+  y- y// y+ y* " on s (space).
We still have to handle the first entry, which should translate into the code Yq. Since Think of a number does not contain any digits, the @? operator returns nil. Using nil as an index into the lookup table also returns nil. Nil is falsy, so all we need to do is add |'q to use q instead of an operation for this case.
The final element of the returned list is the number itself. We obtain this via a@y (find all matches in the command of the digit regex we yanked earlier). This returns a list of digits, but again, it's not a problem because all lists will be concatenated when output. For the first entry, a@y matches no digits and gives empty list, which doesn't add anything to the output.
For example
With input
Think of a number, subtract from 20, add 2, repeat.

the map expression gives the list
[["Y";"q";[]]; ["Y";"-y+";[2;0]]; ["Y";"y+";[2]]; ["Y";"y+";[2]]]

which, when concatenated, outputs
YqY-y+20Yy+2Yy+2

Python 2, 154 153 146 bytes
Fixed, and even saved several bytes in the process. ^__^
for c in input()[9:-1].split(","):s=c.rfind(" ");p=o=s and"x="+"-x+ input() x- x// x+ x*".split()[s%7]+c[s:]*(c[0]<"a")or p;print o
print"print x"

Try it online!
Based on the same strategy as my Pip answer. Python-specific features:

Think of  and the closing . are removed from the string before splitting (input()[9:-1]). The period was too pesky to handle in the main loop. Removing the first nine characters helps for a different reason (see below).
Instead of getting each command's length by regex-searching for a digit (expensive in Python because import re), we use rfind(" ") to find the last space in the command. We can also use this to check for the repeat case.
Python doesn't have Pip's cyclical indexing, so we have to take the index mod 7 explicitly. On the other hand, this means that we can remove the last dummy value in the lookup table, since the index mod 7 is never 6.
The "command" the first time through is a number, in which the index of the space is 1. This index conveniently fills the other hole in the lookup table. The other problem with processing the input stage in the main loop was the +c[s:] part, which would result in x=input() number. To resolve that problem, we string-multiply by c[0]<"a": 1 for all regular commands, in which c starts with a space, but 0 for the initial a number.

WinDbg, 449 388 bytes
as, }@$t1
as. }0;?@$t0
asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
aSa " "
asQ .printf";r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0
as/c add Q +"
aSby " "
as/c divide Q /"
asfrom 0;r$t0=-@$t0+
as/c multiply Q *"
aSnumber " "
aSof " "
asrepeat +1
as/c subtract Q -"
.for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."

-61 bytes by defining alias for repeated code
Inspired by LambdaBeta's use of #define. This approach modifies the WordMath syntax slightly (, and . must be space-delimited like the other words, and , does not follow repeat), and creates alias such that the modified WordMath syntax is valid WinDbg code. The last line does what the question asks and transpiles by converting the input into the modified syntax.
Input is taken by setting a string at a memory address and setting the pseudo-register $t0 to that address. Note: this will overwrite the int at 0x2000000, so if you start your string there, it'll be partly overwritten. $t0 will also be overwritten.
Because it creates aliases, depending on whether this code has run before or after setting teh string, the output code will be different (either aliased or not). Unfortunately, I didn't find a way to get the aliases to properly expand without being whitespace delimited (meaning the WordMath script could not just be executed directly without being transformed first).
How it works:
* $t1 is used for repeating and $t0 is used to read the input and hold the accumulator
* Alias , to }@$t1 -- closing do-while loop and allowing repeat
as , }@$t1

* Alias . to }0;?@$t0 -- close do-while loop and evaluate $t0 (accumulator)
as . }0;?@$t0

* Alias Think to (note this is one line)
as Think n10;               * Set base 10
         ed 8<<22;          * Read ints to address 0x2000000. Enter nothing to exit input mode
         r$t0 = dwo(8<<22); * Set $t0 = first int
         r$t1=0;.do{        * Open do-while

* Alias a to nothing
aS a " "

* Alias add to (note one line):
as add ;                       * Close previous statement
       r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
       r$t0=@$t0+              * Add number to $t0

* Alias by to nothing
aS by " "

* Alias divide to (note one line):
as divide ;                       * Close previous statement
          r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
          r$t0=@$t0/              * Divide next number from $t0

* Alias from to (note one line):
as from 0;         * Preceding subtract statement subtracts 0
       r$t0=-@$t0+ * Subtract $t0 from next number

* Alias multiply to (note one line):
as multiply ;                       * Close previous statement
            r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
            r$t0=@$t0*              * Multiply next number with $t0

* Alias number to nothing
aS number " "

* Alias of to nothing
aS of " "

* Alias repeat to +1 making do-while (once) loops into do-while (once)+1
as repeat +1

* Alias subtract to (note one line):
as subtract ;                       * Close previous statement
            r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
            r$t0=@$t0-              * Subtract next number from $t0

.for (r$t9=1; by(@$t0); r$t0=@$t0+1) * Enumerate the string
{
    j 44!=by(@$t0)                   * If not comma
        .printf "%c",by(@$t0);       * Print the char
    * implicit else
        .if 116!=by(@$t0-1)          * Else if the previous char is not t
        {
          .printf " , "              * Print the comma with spaces around it
        }
};
.printf "\b ."                       * Replacing ending "." with " ."

Sample output, entering the string before running this code once (the resulting program resembles WordMath):
0:000> r$t0=8<<22
0:000> eza8<<22"Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2."
0:000> as, }@$t1
0:000> as. }0;?@$t0
0:000> asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
0:000> aSa " "
0:000> asadd ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+
0:000> aSby " "
0:000> asdivide ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/
0:000> asfrom 0;r$t0=-@$t0+
0:000> asmultiply ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*
0:000> aSnumber " "
0:000> aSof " "
0:000> asrepeat +1
0:000> assubtract ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0-
0:000> .for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."
Think of a number ,  add 5 ,  add 10 ,  multiply by 2 ,  subtract 15 ,  repeat divide by 2 }0;?@$t0

0:000> Think of a number ,  add 5 ,  add 10 ,  multiply by 2 ,  subtract 15 ,  repeat divide by 2 }0;?@$t0
base is 10
02000000 6e696854 18
18
02000004 666f206b

Evaluate expression: 18 = 00000012

Sample output, entering the string after after this code has run once (the aliases are expanded when entering the string so the resulting program is not as pretty):
0:000> r$t0=8<<22
0:000> eza8<<22"Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2."
0:000> as, }@$t1
0:000> as. }0;?@$t0
0:000> asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
0:000> aSa " "
0:000> asadd ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+
0:000> aSby " "
0:000> asdivide ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/
0:000> asfrom 0;r$t0=-@$t0+
0:000> asmultiply ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*
0:000> aSnumber " "
0:000> aSof " "
0:000> asrepeat +1
0:000> assubtract ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0-
0:000> .for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."
n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{     number ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 5 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 10 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*   2 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0- 15 ,  repeat ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/   2 }0;?@$t0

0:000> n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{     number ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 5 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 10 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*   2 ,  ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0- 15 ,  repeat ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/   2 }0;?@$t0
base is 10
02000000 3b30316e 26
26
02000004 3c386465

Evaluate expression: 26 = 0000001a

Some more sample output, just using the slightly modified WordMath syntax:
0:000> Think of a number , add 1 , repeat repeat repeat divide by 3 .
base is 10
02000000 0000001a 3
3
02000004 3c386465

Evaluate expression: 2 = 00000002

0:000> Think of a number , divide by 5 , subtract from 9 .
base is 10
02000000 00000003 29
29
02000004 3c386465

Evaluate expression: 4 = 00000004

Scala, 338 bytes
Try it yourself at ideone
s=>{val n=(_:String)filter(_.isDigit)toInt;(Seq("").tail/:s.split(",").tail)((a,&)=> &match{case&if&contains "v"=>a:+"x/="+n(&)
case&if&contains "d"=>a:+"x+="+n(&)
case&if&contains "y"=>a:+"x*="+n(&)
case&if&contains "f"=>a:+"x="+n(&)+"-x"
case&if&contains "s"=>a:+"x-="+n(&)
case p=>a:+a.last})mkString("var x=readInt;",";",";print(x)")}

Explanation:
// define a function with a parameter s
s => {
    // define a function with a String parameter to extract a number from a string
    val n =
        // filter out the chars that arent't digits
        (_: String) filter (_.isDigit)
        // and parse the number
        toInt;
    // take the tail of a list with an empty string,
    // which is the empty list of type Seq[String].
    // This is the start value for the fold...
    (Seq("").tail /:
        // ... of the tail of the sentence splitted at commas
        s.split(",").tail
    ) (
        // This is the function for the fold.
        // a is the accumulator (the list), and the current element is called &
        (a, &) => & match {
            // if & contains a "v", append "x/=" + n(&) to a.
            case & if & contains "v" => a :+ "x/=" + n(&)
            // the other cases are similar
            case & if & contains "d" => a :+ "x+=" + n(&)
            case & if & contains "y" => a :+ "x*=" + n(&)
            case & if & contains "f" => a :+ "x=" + n(&) + "-x"
            case & if & contains "s" => a :+ "x-=" + n(&)
            // for the repeat, apppend the last value of a to a
            case p                   => a :+ a.last
        }
     )
     // make a string out of the parts by joining them with semicolons,
     // prepending "var x=readInt;" and appending ";print(x)"
     mkString("var x=readInt;", ";", ";print(x)")
}


text:
Binary to decimal converter
Binary to decimal converter
As far as I can see, we don't have a simple binary to decimal conversion challenge.

Write a program or function that takes a positive binary integer and outputs its decimal value.
You are not allowed to use any builtin base conversion functions. Integer-to-decimal functions (e.g., a function that turns 101010 into [1, 0, 1, 0, 1, 0] or "101010") are exempt from this rule and thus allowed.
Rules:

The code must support binary numbers up to the highest numeric value your language supports (by default)
You may choose to have leading zeros in the binary representation
The decimal output may not have leading zeros.
Input and output formats are optional, but there can't be any separators between digits. (1,0,1,0,1,0,1,0) is not a valid input format, but both 10101010 and (["10101010"]) are.

You must take the input in the "normal" direction. 1110 is 14 not 7.

Test cases:
1
1

10
2

101010
42

1101111111010101100101110111001110001000110100110011100000111
2016120520371234567

This challenge is related to a few other challenges, for instance this, this and this.

Related

Does the output have to be unsigned or can it be signed? Also, if my language happens to automatically switch between 32-bit and 64-bit integers depending on the length of the value, can the output be signed in both ranges? Eg- There's two binary values that will convert to decimal -1 (32 1's and 64 1's)

Also, can the output be floating, do does it need to be an integer?

@Carcigenicate It must be an integer, but it can be of any data type. As long as round(x)==x you're fine :) 2.000 is accepted output for 10.

@milk, you may output +42 instead of 42 if you want to. If the language support 64-bit integers without any special type casting or importing then it should behave the same for all numbers from 1 to 2^64-1.

Can I take two parameters (the number of bits, followed by the list of bits)?  Otherwise, running a COW program will run for several minutes for anything larger than 1000000 and several hours for anything with only a couple more bits

The last number is the date the challenge was posted? The hours and seconds don't correspond with SE's UTC+0 time, it should be 20161205193745***** :)

I knew that comment would come sooner or later... Who cares about UTC+0? :)

Can we take the 0 as \00 and 1 as \01?

Jelly, 5 bytes
DḤ+¥/

Try it online!
Explanation

The cast

D is a monad (single argument function): digits, turning 1234 into [1, 2, 3, 4].
Ḥ is a monad that doubles its single argument.
+ is a dyad (two argument function) that adds its left and right arguments.

From there, it gets a little tricky.
Here’s what happens at parse time

D, Ḥ, and + are read. The chain looks like [D, Ḥ, +].
The next two characters are quicks, which act like parse-time postfix operators on the links (functions) we've read so far.
When ¥ is read, the last two links get popped and replaced by a link that acts like the dyad formed by composing them. So now the chain looks like [D, dyad(Ḥ+)].
When / is read, the last link (which ought to be a dyad) gets popped and replaced by a monad that folds using this dyad (intuitively: f/ takes a list, replaces the commas in it with f, and evaluates the result.)
The final chain looks like [D, fold(dyad(Ḥ+))], two monads.

Here's what happens at run time

Input (a number) is implicitly read into the working value (say, 101010).
D is executed, replacing the working value with its digits ([1,0,1,0,1,0]).
fold(dyad(Ḥ+)) is executed, replacing the working value with 1∗0∗1∗0∗1∗0, where ∗ is the dyad Ḥ+.

So what does x∗y evaluate to?

In a dyadic definition, the working value is initially the left argument, x.
Ḥ, the double monad, doubles this value. The working value is now 2x.
+, the plus dyad, lacks a right argument, so this is a hook: a special syntactical pattern where the right argument of this dyad gets injected into +. This yields 2x + y as the final working value, which is returned.

So the whole expression evaluates to:
1∗0∗1∗0∗1∗0 = 2×(2×(2×(2×(2×1+0)+1)+0)+1)+0
            = 32×1 + 16×0 + 8×1 + 4×0 + 2×1 + 1×0
            = 42

Your explanations are getting better and better :-)

Heh, I guess you do it from now on? That's awesome, +1.

I think this is the first piece of Jelly I've ever understood. +1!

Bravo. I actually understand what I initially thought was just a mess of seemingly random characters. Wonderful explanation.

Amazing, but in what encoding is that 5 bytes? Ḥ (U+1E24) is 3 bytes in UTF8 for a total of 7 bytes. If UTF16, then this is 10 bytes.

@Mark Jelly has its own codepage to make the programs look, ahem, readable, but the programs could as well just be bytestrings.

Python 2, 49 37 31 30 Bytes
Now this will take a binary number in a decimal representation, since Python can handle arbitrarily large integers.
b=lambda n:n and n%2+2*b(n/10)

thanks to xnor for saving a byte :)
The easiest way to see how this works is by seeing a basic formula for converting binary to decimal:
= 101010
= 1*(2^5) + 0*(2^4) + 1*(2^3) + 0*(2^2) + 1*(2^1) + 0*(2^0)
= 1*32 + 0*16 + 1*8 + 0*4 + 1*2 + 0*1
= 42

This is a 'standard' way of converting. You can expand the third line like so:
= ((((1*2 + 0)*2 + 1)*2 + 0)*2 + 1)*2 + 0

And this is essentially what the recursive method I've made is doing.
Alternate solutions I had:
b=lambda n:n and n%10+2*b(n/10)
b=lambda n:n%10+2*(n and b(n/10))
b=lambda n:0if n<1else n%10+2*b(n/10)
b=lambda n:0**(n/10)or n%10+2*b(n/10)
b=lambda n,o=0:o*(n<'0')or b(n[1:],2*o+int(n[0]))
lambda j:sum(int(b)*2**a for a,b in enumerate(j,1))

You can do n%5 or n%2 instead of n%10.

@xnor Ah, not sure how I missed that! Thanks :)

05AB1E, 6 bytes
Code:
$¦v·y+

For the explantion, let's take the example 101010. We start with the number 1 (which is represented by the first digit). After that, we have two cases:

If the digit is a 0, multiply the number by 2.
If the digit is a 1, multiply the number by 2 and add 1.

So for the 101010 case, the following is calculated:

101010, start with the number 1.
101010, multiply by two, resulting into 2.
101010, multiply by two and add one, resulting into 5.
101010, multiply by two, resulting into 10.
101010, multiply by two and add one, resulting into 21.
101010, multiply by two, resulting into 42, which is the desired result.

Code explanation:
$         # Push 1 and input
 ¦        # Remove the first character
  v       # For each character (starting with the first)
   ·      #   Multiply the carry number by two
    y+    #   Add the current character (converted automatically to a number)

Uses the CP-1252 encoding. Try it online!

Nice one! (doesn't work for 0 though I just noticed)

@Emigna Yep, luckily your code only needs to work for positive binary numbers.

Didn't even see that part. Very nice then :)

Turing Machine Code, 232 bytes
(Using, as usual, the morphett.info rule table syntax)
While only 40 bytes shorter than the existing solution, that solution uses 12 states whereas this one only uses 4:
0 1 0 l 0
0 0 . r 0
0 . 1 l 0
0 _ I r 1
0 I 2 r 0
0 2 3 r 0
0 3 4 r 0
0 4 5 r 0
0 5 6 r 0
0 6 7 r 0
0 7 8 r 0
0 8 9 r 0
0 9 X l 0
0 X O r 0
0 O I r 0
1 _ _ l 2
1 * * * 0
2 * _ l 3
3 O 0 l 3
3 I 1 l 3
3 . _ l 3
3 _ * * halt
3 * * l 3

Try it online!
The interesting computation (ie. base-conversion) actually just takes place in state 0. This state decrements the binary number one-by-one, each time incrementing a decimal counter.
Due to naming clashes of the number-bases' alphabets, I make use of O and I during the conversion. State 1,2,3 only take care of cleaning the tape, converting the symbols O → 0 and I → 1 and finally halting the machine.

Welcome to Code Golf, and nice first answer!

Haskell, 16 111 + 57 = 168 bytes
import Data.String
instance IsString[Int]where fromString=map((-48+).fromEnum)
f::[Int]->Int
f=foldl1((+).(2*))

+57 bytes for the compile flags -XOverloadedStrings, -XOverlappingInstances and -XFlexibleInstances.
The challenge has some cumbersome IO format, because it heavily depends on how data types are expressed in the source code. My first version (16 bytes), namely
foldl1((+).(2*))

takes a list of integers, e.g. [1,0,1,0,1,0] and was declared invalid because literal Haskell lists happen to have , between the elements. Lists per se are not forbidden. In my new version I use the very same function, now named f, but I overload "Quote enclosed character sequences". The function still takes a list of integers as you can see in the type annotation [Int] -> Int, but lists with single digit integers can now be written like "1234", e.g.
f "101010"

which evaluates to 42. Unlucky Haskell, because the native list format doesn't fit the challenge rules. Btw, f [1,0,1,0,1,0] still works.

Unfortunately a list is not a valid input.

@JonathanAllan: Why? And if so, how should it take input at all? In Haskell a string is just a list of characters.

I don't know why ...but I enquired about this early on and an edit was made to add "(1,0,1,0,1,0,1,0) is not a valid input format, but both 10101010 and (["10101010"]) are." furthermore a comment suggests the array of characters is acceptable if that is how a string input is interpreted.

@JonathanAllan: my function takes a list. Lists don't have , between the elements. String representations of literal lists have , between the elements, but there are other ways where lists can come from, e.g. return values of other functions. As we don't have to take input of type string, no string representation is involved. let list = "abc" >> fromEnum.not <$> [False ..] in foldl1((+).(2*)) list also evaluates to 42. The intermediate list list is never turned into a string, so there are no separators like , involved.

A list is inherently separated, it was not just the character , that was banned. I asked if lists were OK and the response was a comment saying the edit had been made (including "there can't be any separators between digits"), which I understood to be "No"; maybe I misunderstood, maybe @StewieGriffin could let me know.

@JonathanAllan: any "binary integer" (the input we have to take) is inherently separated, it's a sequence of powers of 2. The restriction is about explicit separators (between the digits) and not about separation. Somehow I have to take separated digits.

Note how other answers are using extra bytes to take strings or decimal representations over lists, including Lynn's Jelly answer (in Jelly a string is also just a list of characters), which would be 4 bytes not 5 with Ḥ+¥/ rather than DḤ+¥/.

@JonathanAllan: the rules, as written, do not forbid lists or lists of integers, just sequences that contain additional separators between the digits. My claim as discussed above: lists don't contain separators per se. Of course the elements (here: binary digits) are separated, because we have a few of them. For example, the string "1,0,1" is not allowed, because it has 5 characters but only 3 digits - the other two characters are separators. -- PS: last post for today, it's already late here.

Op here: if it's possible to input 10101010 ,  "10101010" or something similar and make it work then the submission is valid. You may call it a string, list, integer or whatever.  Inputting [1][0][1][0] or [1,0,1,0] is not ok. Basically, it should be possible to just hit a bunch of ones and zeros in a row somewhere. Is this clear?

@StewieGriffin: better, now?

JavaScript (ES6), 33 31 bytes
s=>[...s].map(c=>r+=+c+r,r=0)|r

Edit: Shorter but less sweet: 2 bytes saved thanks to @ETHproductions.

As is often the case, .map is shorter: s=>[...s].map(c=>+c+r+r,r=0)|r

@ETHproductions How does your function return anything other than 0?

Sorry, it should be s=>[...s].map(c=>r+=+c+r,r=0)|r

Labyrinth, 17 15 bytes
-+:
8 +
4_,`)/!

Try it online!

Labyrinth is a two-dimensional, stack-based language. In labyrinth, code execution follows the path of the code like a maze with spaces acting as walls and beginning at the top-left-most non-space character. The code flow is determined by the sign of the top of the stack. Since the stack has implicit zeroes at the bottom, the first four instructions (-+:+) have no effect.
Loop starting at the ,

, Push the ascii code value of the next input character to the stop of the stack, or push -1 if EOF.
_48 pushes 48 to the top of the stack
- Pop y, pop x, push x-y. The previous instructions have the effect of subtracting 48 from the input yielding 0 for "0" and 1 for "1".
+ Pop y, pop x, push x+y.
: Duplicate the top of the stack
+ This and the previous instruction have the effect of multiplying the current value by 2

So the circular part of the code, in effect, multiples the current number by 2 and adds either a 1 or a 0 depending on if the character 1 or 0 was input.
Tail
If the top of the stack is negative (meaning EOF was found), the code will turn left at the junction (going towards the semicolon).

``` Negate the top of the stack to get 1
) Icrement the top of the stack to get 2
/ Pop y, pop x, push x/y (integer division). This has the effect of undoing the last *2 from the loop.
! Output the integer representation of the top of the stack. At this point the program turns around because it hit a dead end and then exits with an error because it tries to divide by zero.

Thanks to @Martin Ender for saving me 2 bytes (and teaching me how to better think in Labyrinth).

Instead of _48- you can simply do #% but unfortunately I don't see how it might help with the byte count.

You can save a byte with \)instead of;_2` though.

@MartinEnder, I don't understand your comment about #%. Can you explain how that works as a replacement for _48- to convert from ascii to int. Thanks for the ) tip. I'll make that change.

At that point in your program there are always two values on the stack so # is just short for _2. While _2% isn't a general conversion method for ASCII to integer, it works here because you're only interested in the first two digits as possible input. An alternative would be _1& (since modulo 2 simply extracts the least significant bit).

Oh. That's brilliant. But yeah I'm not sure how to use that substitution (#%) to shorten the code overall.

The only possibility I can think of is decomposing the main loop into multiple 2x2 loops, which can often save bytes but is also usually very tricky. Not sure whether it's possible here.

Btw you also don't need the @. The / is going to terminate the program for you after the IP turns around.

Retina, 15 bytes
Converts from binary to unary, then unary to decimal.
1
01
+`10
011
1

Try it online

You are not allowed to use any builtin base conversion functions. ~OP

@RomanGräf There aren't any. I was simply describing the process of my solution.

PHP, 44 bytes
for(;""<$c=$argv[1][$i++];)$n+=$n+$c;echo$n;

I could have sworn that I´ve seen that question before. But well.
Reads the number from left to right, shifts left and adds the current bit.

Brain-Flak, 46, 28 bytes
([]){{}({}<>({}){})<>([])}<>

Try it online!
Many many bytes saved thanks to @Riley!
Since brain-flak can't take binary input, input is a list of '0's and '1's.
Explanation:
#Push the height of the stack
([])

#While true:
{

 #Pop the height of the stack
 {}

 #Push this top number to (the other stack * 2)
 ({}<>({}){})

 #Toggle back on to the main stack
 <>

 #Push the new height of the stack
 ([])

#endwhile
}

#Toggle back to the other stack, implicitly display.
<>

Love the explanation! So hard to read brain-flak without it :)

^. I can't even read my own programs if I don't leave myself a few comments.

You can get it down to 32 bytes by getting rid of the whole if part,and  for the step "add number to other stack" just add it to the (other stack)*2. ([]){({}[()]<({}<>({}){})><>)}<>

And you can save another 4 by just popping at the start of the while and pushing the height again at the end. ([]){{}({}<>({}){})<>([])}<>

@Riley Oh my gosh, that's genius. Thankyou very much!

Java, 84 79 46 48 bytes

Version 3.1

Changed to long/48 bytes:
s->{long x=0;for(char c:s)x=c-48l+x*2;return x;}

Version 3.0

Did some golfing/46 bytes:
s->{int x=0;for(char c:s)x=c-48+x*2;return x;}

Version 2.0

Thanks to @Geobits!/79 bytes:
s->{int i=Math.pow(2,s.length-1),j=0;for(char c:s){j+=c>48?i:0;i/=2;}return j;}

Version 1.0

84 bytes:
s->{for(int i=-1,j=0;++i<s.length;)if(s[i]>48)j+=Math.pow(2,s.length-i+1);return j;}

guess i should have done an iterative solution. lulz. good job

Is your input type List or String? If it's the latter, I was unaware Java8 could do that! If it's the former is that allowed by the challenge?

s should be char[]. I hope that's allowed...

What is the return type here? I think it should be long because "The code must support binary numbers up to the highest numeric value your language supports" per the OP but for smaller values I would think it returns an int

I think char[] is generally allowed as a String representation. I was just unsure because of the clarification in the OP

It returns an int. I think it costs 2 bytes to change to long.

Probably fine on input type per this. Might want to take the 2 byte hit for output imo

Just FYI, we can view the edit history to see previous versions of the code. You don't need to keep them all in your answer.

C# 6, 85 37 36 bytes
long b(long n)=>n>0?n%2+2*b(n/10):0;

Thanks to Kade for saving 41 bytes!
Changing to C# 6 saved another 7 bytes.

Maybe this could provide some inspiration? ;)

@Kade It does, thanks! I was looking at the Python answer which uses the same technique at the same moment you linked that :D I can get even shorter with C# 6.

Befunge-98, 12 bytes
2j@.~2%\2*+

Try it online!
Reads one char at a time from input, converts it to 0 or 1 by taking its value modulo 2 (0 is char(48), 1 is char(49)), then uses the usual algorithm of doubling the current value and adding the new digit each time.
Bonus:
This works with any kind of input string, I've been trying for a while now to find any funny input->output combination, but I wasn't able to produce anything (sadly, "answer"=46). Can you?

LOL. I was playing the same game with my answer. Most interesting number I could generate was 666.

Nice one! I hadn't managed to find anything fitting for 666 :D It would be a lot easier if capitalization had an effect on values...

@James Holderness - I've been doing the same and I've only found 'theleapyear' to bring back 366, yours is really good.

Javascript (ES7) 41 40 36 bytes
f=([c,...b])=>c?c*2**b.length+f(b):0

takes a string as input
Shaved a byte thanks to ETHproductions

f=([c,...b])=>c?c*2**b.length+f(b):0
document.write([
    f('101010'),
    f('11010'),
    f('10111111110'),
    f('1011110010110'),
].join("<br>"))

The right-to-left associativity of ** is weird, but nice job using it here. 1<<b.length would do the same thing, but it would require parentheses to keep from being parsed as (c*1)<<(b.length+...). I think you can save a byte by replacing b[0] with b+b (see here).

Perl, 25 bytes
-3 bytes thanks to @Dom Hastings.
24 bytes of code + 1 byte for -p flag.
$\|=$&<<$v++while s/.$//

To run it:
perl -pe '$\|=$&<<$v++while s/.$//' <<< 101010

Explanations:
$\|=$&<<$v++  # Note that: we use $\ to store the result
              # at first $v=0, and each time it's incremented by one
              # $& contains the current bit (matched with the regex, see bellow)
              # So this operation sets a $v-th bit of $\ to the value of the $v-th bit of the input
while         # keep doing this while...
s/.$//        #  ... there is a character at the end of the string, which we remove.
         # $\ is implicitly printed thanks to -p flag

21 bytes, Try it online!

Vyxal s, 31 bitsv2,  9   7  3.875 bytes
fṘTE

Try it Online!
fṘTE

Try it Online!

-2 thanks to Steffan
-3 chars thanks to lyxal

Explanation:
fṘTE  # Implicit input
f     # Flatten into a list of digits
 Ṙ    # Reverse the list
  T   # Truthy indices
   E  # Two power
      # Implicit output of sum

Old:
ṘėRvƒ↲∑    # Implicit input
Ṙė         # Reverse and enumerate
  R        # Reverse each
   vƒ      # Vecorised reduce over:
     ↲     # Left bit-shift
      ∑    # Sum
           # Implicit output

"You are not allowed to use any builtin base conversion functions."

Sorry, I didn't see that. I've updated the answer

7 bytes: ṘėRvƒ↲∑ (a*2**b is a<<b, or ↲)

R is "reverse each" in this case, not "reduce". vƒ↲ is vectorized reduce over left bit-shift (it's ƒ not f)

@Steffan thanks

But the following sentence says that: Integer-to-decimal functions are exempt from this rule and thus allowed. That' a bit confusing for me Steffan.

Try it Online! for 3.875 bytes

05AB1E, 7 bytes
RvNoy*O

Try it online!
Explanation
R         # reverse input
 v     O  # sum of
  No      # 2^index
     *    # times
    y     # digit

Bash + GNU utilities, 29 bytes
sed 's/./2*&+/g;s/.*/K&p/'|dc

I/O via stdin/stdout.
The sed expression splits the binary up into each digit and builds a RPN expression for dc to evaluate.

C, 53
v(char*s){int v=0,c;while(c=*s++)v+=v+c-48;return v;}

Same as my javascript answer
Test Ideone

You can save 4 bytes by declaring v and c as global variables (though you need to change the name of v, since it's already the name of the function) like this: w=0;c;v(char*s){while(c=*s++)w+=w+c-48;return w;}

@Steadybox it could be w,c; but I don't want use globals when the answer is a function (even in code-golf)

@Steadybox Globals defaults to 0 as well, so you can drop the =0.

Retina, 12 bytes
Byte count assumes ISO 8859-1 encoding.
+%`\B
¶$`:
1

Try it online!
Alternative solution:
+1`\B
:$`:
1

Explanation
This will probably be easier to explain based on my old, less golfed, version and then showing how I shortened it. I used to convert binary to decimal like this:
^
,
+`,(.)
$`$1,
1

The only sensible way to construct a decimal number in Retina is by counting things (because Retina has a couple of features that let it print a decimal number representing an amount). So really the only possible approach is to convert the binary to unary, and then to count the number of unary digits. The last line does the counting, so the first four convert binary to unary.
How do we do that? In general, to convert from a list of bits to an integer, we initialise the result to 0 and then go through the bits from most to least significant, double the value we already have and add the current bit. E.g. if the binary number is 1011, we'd really compute:
(((0 * 2 + 1) * 2 + 0) * 2 + 1) * 2 + 1 = 11
           ^        ^        ^        ^

Where I've marked the individual bits for clarity.
The trick to doing this in unary is a) that doubling simply means repeating the number and b) since we're counting the 1s at the end, we don't even need to distinguish between 0s and 1s in the process. This will become clearer in a second.
What the program does is that it first adds a comma to the beginning as marker for how much of the input we've already processed:
^
,

Left of the marker, we'll have the value we're accumulating (which is correctly initialised to the unary representation of zero), and right of the value will be the next bit to process. Now we apply the following substitution in a loop:
,(.)
$`$1,

Just looking at ,(.) and $1,, this moves the marker one bit to the right each time. But we also insert $`, which is everything in front of the marker, i.e. the current value, which we're doubling. Here are the individual steps when processing input 1011, where I've marked the result of inserting $` above each line (it's empty for the first step):
,1011

1,011
 _
110,11
   ___
1101101,1
       _______
110110111011011,

You'll see that we've retained and doubled the zero along with everything else, but since we're disregarding them at the end, it doesn't matter how often we've doubled them, as long as the number of 1s is correct. If you count them, there are 11 of them, just what we need.
So that leaves the question of how to golf this down to 12 bytes. The most expensive part of the 18-byte version is having to use the marker. The goal is to get rid of that. We really want to double the prefix of every bit, so a first idea might be this:
.
$`$&

The problem is that these substitutions happen simultaneously, so first bit doesn't get doubled for each bit, but it just gets copied once each time. For input 1011 we'd get (marking the inserted $`):
 _ __ ___
1101011011

We do still need to process the input recursively so that the doubled first prefix is doubled again by the second and so on. One idea is to insert markers everywhere and repeatedly replace them with the prefix:
\B
,
+%`,
¶$`

After replacing each marker with the prefix for the first time, we need to remember where the beginning of the input was, so we insert linefeeds as well and use the % option to make sure that the next $` only picks up things up the closest linefeed.
This does work, but it's still too long (16 bytes when counting 1s at the end). How about we turn things around? The places where we want to insert markers are identified by \B (a position between two digits). Why don't we simply insert prefixes into those positions? This almost works, but the difference is that in the previous solution, we actually removed one marker in each substitution, and that's important to make the process terminate. However, the \B aren't character but just positions, so nothing gets removed. We can however stop the \B from matching by instead inserting a non-digit character into this place. That turns the non-word boundary into a word boundary, which is the equivalent of removing the marker character earlier. And that's what the 12-byte solution does:
+%`\B
¶$`:

Just for completeness, here are the individual steps of processing 1011, with an empty line after each step:
1
1:0
10:1
101:1

1
1:0
1
1:0:1
1
1:0
10:1:1

1
1:0
1
1:0:1
1
1:0
1
1:0:1:1

Again, you'll find that the last result contains exactly 11 1s.
As an exercise for the reader, can you see how this generalises quite easily to other bases (for a few additional bytes per increment in the base)?

Pushy, 10 bytes
Takes input as a list of 0/1 on the command line: $ pushy binary.pshy 1,0,1,0,1,0.
L:vK2*;OS#

The algorithm really shows the beauty of having a second stack:
            \ Implicit: Input on stack
L:    ;     \ len(input) times do:
  v         \   Push last number to auxiliary stack
   K2*      \   Double all items
       OS#  \ Output sum of auxiliary stack

This method works because the stack will be doubled stack length - n times before reaching number n, which is then dumped into the second stack for later. Here's what the process looks like for input 101010:

1: [1,0,1,0,1,0]
2: []

1: [2,0,2,0,2]
2: [0]

1: [4,0,4,0]
2: [2]

1: [8,0,8]
2: [2,0]

1: [16,0]
2: [2,0,8]

1: [32]
2: [2,0,8,0]

1: []
2: [2,0,8,0,32]

2 + 8 + 32 -> 42

Mathematica, 27 13 11 bytes
Fold[#+##&]

Accepts a List of bits as input (e.g. {1, 0, 1, 1, 0} -- Mathematica's binary representation of the number 22)

Following up from the comment on Greg's answer, how is "splitting all the digits in the input" not a base conversion function?

@MartinEnder I'm using it like the Characters function.

@MartinEnder Actually, as seen in @nimi's answer, I could just accept a list of 1s and 0s because that is the only way to represent a binary number in Mathematica, meaning I don't need IntegerDigits in the first place.

That assumes that base 10 is the "natural" representation of an integer. An actual integer value has no preferred base attached to it (I guess you could say the way it's stored is probably base 256 or maybe even base 2 but that's an implementation detail). Just because we (normally) use base 10 to write integer literals there doesn't mean integer values are already in base 10.

@MartinEnder @Lynn's Jelly code uses D, which does the same thing as IntegerDigits

well then I think that's invalid too. I guess I'll ask the OP.

Actually, Dennis already did.

http://codegolf.stackexchange.com/questions/102219/binary-to-decimal-converter/102223#comment248521_102223 (discussion on digit extraction built-ins is still happening)

So the result of the discussion was that IntegerDigits is valid but taking list input isn't.

R (32-bit), 64 Bytes
Input for the function should be given as character. The base functions of R support 32-bit integers.
Input:
# 32-bit version (base)
f=function(x)sum(as.double(el(strsplit(x,"")))*2^(nchar(x):1-1))
f("1")
f("10")
f("101010")
f("1101111111010101100101110111001110001000110100110011100000111")

Output:
> f("1")
[1] 1
> f("10")
[1] 2
> f("101010")
[1] 42
> f("1101111111010101100101110111001110001000110100110011100000111")
[1] 2.016121e+18

R (64-bit), 74 Bytes
Input for the function should be given as character. The package bit64 has to be used for 64-bit integers.
Input:
# 64-bit version (bit64)
g=function(x)sum(bit64::as.integer64(el(strsplit(x,"")))*2^(nchar(x):1-1))
g("1")
g("10")
g("101010")
g("1101111111010101100101110111001110001000110100110011100000111")

Output:
> g("1")
integer64
[1] 1
> g("10")
integer64
[1] 2
> g("101010")
integer64
[1] 42
> g("1101111111010101100101110111001110001000110100110011100000111")
integer64
[1] 2016120520371234567

You can do: el(strsplit(x,"")) instead of strsplit(x,split="")[[1]] to save a couple of bytes.

Thanks a lot! Especially for the el function - I was not aware of it.

Matlab, 30 Bytes
@(x)sum(2.^find(flip(x)-48)/2)

The last test case has rounding errors (because of double), so if you need full precision:
@(x)sum(2.^uint64(find(flip(x)-48))/2,'native')

with 47 Bytes.

I can't test this, but I believe @(x)sum(2.^(find(flip(x)-48)-1)) will give the correct result for all cases for 32 bytes. flip works like fliplr if x is one dimensional.

Nice solution! I also ran into the rounding error, thanks for the fix.  What is the format of x? Calling flip or fliplr on a number just returns that number.

x is the binary string, so call it with f=@(x)..; f('1111001010').

Elm, 60 41 bytes
String.foldl(\b a->2*a+Char.toCode b-48)0

-19 bytes thanks to Wheat Wizard and alephalpha
You can try it here. Here's a full test snippet:
import Html exposing (text)

f : String -> Int
f=String.foldl(\b a->2*a+Char.toCode b-48)0

main = text (String.fromInt (f "101010"))

Since you only use n once you can very easily express this using point free to save 4 bytes.

You can use String.foldl instead of List.Foldl + String.toList.

You don't need to count the f= since the body is a valid anonymous function.

PowerShell v2+, 55 bytes
param($n)$j=1;$n[$n.length..0]|%{$i+=+"$_"*$j;$j*=2};$i

Feels too long ... Can't seem to golf it down any -- tips appreciated.
Explanation
param($n)$j=1;$n[$n.length..0]|%{$i+=+"$_"*$j;$j*=2};$i
param($n)$j=1;                                          # Take input $n as string, set $j=1
              $n[$n.length..0]                          # Reverses, also converts to char-array
                              |%{                  };   # Loop over that array
                                 $i+=+"$_"*$j;          # Increment by current value of $j times current digit
                                              $j*=2     # Increase $j for next loop iteration
                                                     $i # Leave $i on pipeline
                                                        # Implicit output

T-SQL, 202 Bytes
DECLARE @b varchar(max)='1',@ int=1 declare @l int=LEN(@b)declare @o bigint=CAST(SUBSTRING(@b,@l,1)AS bigint)WHILE @<@l BEGIN SET @o=@o+POWER(CAST(SUBSTRING(@b,@l-@,1)*2AS bigint),@)SET @=@+1 END PRINT @o

PHP, 64 bytes
foreach(str_split(strrev($argv[1]))as$k=>$v)$t+=$v*2**$k;echo$t;

We reverse our binary number, split it into its component digits, and sum them based on position.

Clojure, 114 105 63 41 bytes
V4: 41 bytes
-22 bytes thanks to @cliffroot. Since digit is a character, it can be converted to it's code via int, then have 48 subtracted from it to get the actual number. The map was also factored out. I don't know why it seemed necessary.
#(reduce(fn[a d](+(* a 2)(-(int d)48)))%)

V3: 63 bytes
(fn[s](reduce #(+(* %1 2)%2)(map #(Integer/parseInt(str %))s)))

-42 bytes (!) by peeking at other answers. My "zipping" was evidently very naïve. Instead of raising 2 to the current place's power, then multiplying it by the current digit and adding the result to the accumulator, it just multiplies the accumulator by 2, adds on the current digit, then adds it to the accumulator. Also converted the reducing function to a macro to shave off a bit.
Thanks to @nimi, and @Adnan!
Ungolfed:
(defn to-dec [binary-str]
  (reduce (fn [acc digit]
            (+ (* acc 2) digit))
          (map #(Integer/parseInt (str %)) binary-str)))

V2: 105 bytes
#(reduce(fn[a[p d]](+ a(*(Integer/parseInt(str d))(long(Math/pow 2 p)))))0(map vector(range)(reverse %)))

-9 bytes by reversing the string so I don't need to create an awkward descending range.
V1: 114 bytes
Well, I'm certainly not winning! In my defense, this is the first program I've ever written that converts between bases, so I had to learn how to do it. It also doesn't help that Math/pow returns a double that requires converting from, and Integer/parseInt doesn't accept a character, so the digit needs to be wrapped prior to passing.
#(reduce(fn[a[p d]](+ a(*(Integer/parseInt(str d))(long(Math/pow 2 p)))))0(map vector(range(dec(count %))-1 -1)%))

Zips the string with a descending index representing the place number. Reduces over the resulting list.
Ungolfed:
(defn to-dec [binary-str]
  (reduce (fn [acc [place digit]]
            (let [parsed-digit (Integer/parseInt (str digit))
                  place-value (long (Math/pow 2 place))]
              (+ acc (* parsed-digit place-value))))
          0
          (map vector (range (dec (count binary-str)) -1 -1) binary-str)))

#(reduce(fn[a b](+(* a 2)(-(int b)48)))0 %) improved version. Moved map part of code directly into reduce, changed integer parsing method, make external function with shorthand lambda syntax.

@cliffroot int can be used to parse!? That'll knock off like 10 bytes in every challenge I've done here lol.

Oh, I see what you're doing. Taking the ascii code, then subtracting to get the value. I guess this would only work in select circumstances only. Oh well, thanks for the tip.

Perl, 21 19 16 + 4 = 20 bytes
-4 bytes thanks to @Dada
Run with -F -p (including the extra space after the F).  Pipe values to the function using echo -n
$\+=$_+$\for@F}{

Run as echo -n "101010" | perl -F -pE '$\+=$_+$\for@F}{'
I feel this is sufficiently different from @Dada's answer that it merits its own entry.
Explanation:
-F                              #Splits the input character by character into the @F array
-p                              #Wraps the entire program in while(<>){ ... print} turning it into
while(<>){$\+=$_+$\for@F}{print}
                   for@F        #Loops through the @F array in order ($_ as alias), and...
          $\+=$_+$\             #...doubles $\, and then adds $_ to it (0 or 1)...
while(<>){              }       #...as long as there is input.
                         {print}#Prints the contents of $_ (empty outside of its scope), followed by the output record separator $\

This uses my personal algorithm of choice for binary-to-decimal conversion.  Given a binary number, start your accumulator at 0, and go through its bits one by one.  Double the accumulator each bit, then add the bit itself to your accumulator, and you end up with the decimal value.  It works because each bit ends up being doubled the appropriate number of times for its position based on how many more bits are left in the original binary number.

Even shorter : perl -F -pE '$\+=$_+$\for@F}{'

I honestly laughed at how short this is now.  Thank you.

Yea, it's pretty neat, well done!

Dyalog APL, 12 bytes
(++⊢)/⌽⍎¨⍞

⍞ get string input
⍎¨ convert each character to number
⌽ reverse
(...)/ insert the following function between the numbers
 ++⊢ the sum of the arguments plus the right argument

ngn shaved 2 bytes.

Haskell, 31 bytes
f=foldl(\a b->2*a+(read$b:[]))0

Takes input in string format (e.g. "1111"). Produces output in integer format (e.g. 15).
:[] Converts from an element to an array -- in this chase from Char to [Char] (String).
read Converts from string to whatever context it's in (in this case the context is addition, so converts to Num)
so (read$b:[]) converts b from Char to Num.
a is the accumulator, so multiply that by two and add the Num version of b.
If input in the format [1,1,1,1] was allowed, the 18 byte
f=foldl((+).(2*))0

would work, but since it's not, it doesn't.

MATL, 7 bytes
PoofqWs

Try it online!
P   % Implicitly input string. Reverse
o   % Convert to array of ASCII codes
o   % Modulo 2: '1' becomes 1, '0' becomes 0
f   % Find: push array of 1-based indices of nonzeros
q   % Subtract 1 from each entry
W   % 2 raised to each entry
s   % Sum of array. Implicitly display

My mind went Poof!

JavaScript (ES6), 32 bytes
f=([...n])=>n+n&&+n.pop()+2*f(n)

Recursion saves the day again! Though the parameterization seems a little long...

Since it's a single "argument", does [...n] need to be surrounded in parentheses?

@Cyoce Unfortunately, yes, or JS throws a SyntaxError.

x86-16 machine code, 10 bytes
Binary:
00000000: 31d2 acd0 e811 d2e2 f9c3                 1.........

Listing:
31 D2       XOR  DX, DX         ; clear output value
        CHRLOOP:
AC          LODSB               ; load next char into AL
D0 E8       SHR  AL, 1          ; CF = LSb of ASCII char
11 D2       ADC  DX, DX         ; shift CF left into result
E2 F9       LOOP CHRLOOP        ; loop until end of string
C3          RET                 ; return to caller

Callable function, input string in [SI] length in CX. Result in DX.
Example test program I/O:

Why the downvote?  Is there a bug, issue or problem with it?

7, 25 bytes (65 characters)
07717134200446170134271600446170001755630036117700136161177546635

Try it online!
Explanation

077                             Initialize counter to 0 (an empty section)
   17134200..77546635           Push the main loop onto the frame

Once the original code has finished executing, the frame is ||6||7134200447013427160044700017556300377700136177754635
The last section of this is the main loop, which will run repeatedly until it gets deleted. All of it except the last two commands is data and section separators, which push commands onto the frame to leave it as:

||6|| (main loop) |73426644|6734216644|6667553663||00137||54

3 outputs the last section (54) and discards the last two bars. On the first iteration, 5 is interpreted as a switch to output format 5 ("US-TTY"), which converts each pair of commands to a character. The 4 following it does not form a group, so it is ignored. On future iterations, we are already in output format 5, so 54 is interpreted as a group meaning "input character". To do this, the character from STDIN is converted into its character code (or, on EOF, -1), and 1 is added. Then, the last section (which is now the 00137) is repeated that many times. In summary:

If the character is 0, 00137 is repeated 49 times.
If the character is 1, 00137 is repeated 50 times.
If there are no more characters, 00137 is repeated 0 times (i.e. deleted).
If this was the first iteration, 00137 is left alone (i.e. repeated 1 time).

5 removes the last section (00137 repeated some number of times) from the frame and executes it, resulting in this many sections containing 6673.
The main loop has now finished executing, so the last section (which is 6673 unless we reached EOF) runs. 66 concatenates the last three sections into one (and has some other effects that don't affect the number of sections), which 73 deletes. Thus, the last three sections are deleted, and this repeats until the last section is no longer 6673.

If we reached EOF, nothing happens.
If this is the first iteration or the character was 0, after removing the last three sections 0 or 16 times, there is just one copy left on the frame. This copy deletes itself and the two sections before it, leaving everything up to the main loop and the section after it.
If the character was 1, after removing the last three sections 17 times, all 50 copies and the third section after the main loop (the EOF handler) have been deleted.

Now, the last section left on the frame runs. This could, depending on the inputted character, be any of the three sections after the main loop.
If this is the first iteration or the character was 0, the section just after the main loop, 73426644, runs.
73 deletes this section, and 4 swaps the main loop with the counter behind it. This counter keeps track of the number we want to output, stored as the number of 7s and 1s minus the number of 6s and 0s. This metric has the property that it is not changed by pacification (which changes some 6s into 0s, some 7s into 1s, and sometimes inserts 7...6 around code). 2 duplicates the counter and 6 concatenates the two copies (after pacifying the second, which, as we saw, does not change the value it represents), so the value is doubled. If this was the first iteration, the counter was previously empty, and doubling it still results in an empty section. Then, 6 gets rid of the empty section inserted by 4 (and pacifies the counter again, leaving the value unchanged), and 44 swaps the counter back to its original position. This leaves two empty sections on the end of the frame, which are removed automatically, and the main loop runs again.
If the character was 1, the second section after the main loop (6734216644) runs. This is just like the section before it (explained in the last paragraph), except for two extra commands: a 6 at the start, which joins the section with the previous one before 73 deletes it, and a 1 in the middle, which adds a 7 to the counter (increasing its value by 1) after it gets doubled.
If we reached EOF, the third section after the main loop (6667553663) runs. 666 joins the last four sections (everything after the counter) into one section, to be deleted by 3. 7553 exits output format 5 by outputting 55 and deletes the section before it, leaving only ||6| (counter) on the frame. 66 pacifies the two sections and combines them, turning the 6 back into a 0 (and not changing the value of the counter). Finally, the last 3 outputs everything.
The 0 at the start enters output format 0 ("Numerical output"), and the rest of the section (i.e. the counter) is converted to a number by taking the number of 7s and 1s minus the number of 6s and 0s. This value, which is the input converted from binary, is output in decimal and the program terminates.

Excel, 74 70 55
Trailing parens already discounted. Tested in Excel Online.
Formulae:

A1: Input
B1: =LEN(A1) (7)

Main Code (48):
A pretty simple "add all the powers of 2" formula:
=SUM(MID(A1,1+B1-SEQUENCE(B1),1)/2*2^SEQUENCE(B1))

Verify with:
=DECIMAL(A1,2)

R, 48 37 bytes
-11 bytes thanks to Dominic van Essen
sum(utf8ToInt(scan(,""))%%2*2^(31:0))

Takes input as a string, left-padded with 0s to 32 bits. Try it online!
I copied some good ideas from djhurio's much earlier R answer, so go give that an upvote too. As with the first solution there, this solution won't work for the last test case because it's too large to fit into R's default size of integer.
Explanation
To get a vector of the bits as integers 0 and 1, we use uft8ToInt to convert to a vector of character codes. This gives us a list of 48s and 49s, which we take mod 2 to get 0s and 1s.
Then, to get the appropriate powers of 2 in descending order, we construct a range from 31 down to 0. Then we convert each of those numbers to the corresponding power of two (2^).
Finally, we multiply the two vectors together and return their sum.

37 bytes (or 40 bytes as a function) thanks to 'You may choose to have leading zeros in the binary representation'.  Accepts input as 32-bit binary string, with leading zeros, but easily modified to double-integer precision for the same length code...

K (ngn/k), 11 10 bytes
(+/2 1*,)/

Try it online!

C, 48 bytes
i;f(char *s){for(i=0;*++s;i+=i+*s-48);return i;}

Heavily inspired by @edc45 's answer but I made some significant changes. I made 'i' a global variable to save having to typecast. I also used a for loop to save a few bytes. It does now require a single leading 0 in the binary representation.
More readable version
f(char *s){
  int i = 0; // Total decimal counter
  for(;;*++s;i+=i+*s-48); // Shift left and add 0 or 1 depending on charecter
  return i;
}

k, 8 bytes
Same method as the Haskell answer above.
{y+2*x}/

Example:
{y+2*x}/1101111111010101100101110111001110001000110100110011100000111b
2016120520371234567

Java 7, 87 bytes
long c(String b){int a=b.length()-1;return a<0?0:b.charAt(a)-48+2*c(b.substring(0,a));}

For some reason I always go straight to recursion. Looks like an iterative solution works a bit nicer in this case...

JavaScript (ES7), 56 47 bytes
Reverses a binary string, then adds each digit's value to the sum.
n=>[...n].reverse().reduce((s,d,i)=>s+d*2**i,0)

Demo

f=n=>[...n].reverse().reduce((s,d,i)=>s+d*2**i,0)
document.write( f('101010') ) // 42

MATL, 8, 7 bytes
"@oovsE

Try it online!
One byte saved thanks to @LuisMendo!
Alternate approach: (9 bytes)
ootn:PW*s

JavaScript, 18 83 bytes
f=n=>parseInt(n,2)
f=n=>n.split('').reverse().reduce(function(x,y,i){return(+y)?x+Math.pow(2,i):x;},0)
Demo

f=n=>n.split('').reverse().reduce(function(x,y,i){return(+y)?x+Math.pow(2,i):x;},0)
document.write(f('1011')) // 11

Uses a built-in, which is disallowed.

@TuukkaX Ah, missed that. Thanks.

I was just about to do the same thing (in c#), I'm bad at reading.

It's a code golf challenge, try to write short code. (y==='1') could be +y

JavaScript (ES6), 38
Simple is better
s=>eval("for(i=v=0;c=s[i++];)v+=+c+v")

Test

f=s=>eval("for(i=v=0;c=s[i++];)v+=+c+v")

console.log("Test 0 to 99999")
for(e=n=0;n<100000;n++)
{
  b=n.toString(2)
  r=f(b)
  if(r!=n)console.log(++e,n,b,r)
}
console.log(e+" errors")

C, 41 37 bytes
i;b(char*s){i+=i+*s++%2;i=*s?b(s):i;}

Wandbox

MATLAB, 49 bytes
@(a)dot(int2str(a)-'0',2.^(floor(log10(a)):-1:0))

Anonymous function that splits the input into an array with int2str(a)-'0', then does a dot product with powers of 2. Has rounding error for the last test case, will update the solution when I figure out a fix.

Forth (gforth 0.7.3), 47 bytes
: x 2 base ! bl parse s>number drop decimal . ;

: x - define new word with name 'x'
2 base ! - set base to binary
bl parse - read line until a space (bl) or EOL
s>number - try to convert the string to number
drop - we only want the converted number and not the success flag
decimal - set base to decimal
. - print value on top of stack
; - end of definition
Test cases:
x 1 1  ok
x 10 2  ok
x 101010 42  ok
x 1101111111010101100101110111001110001000110100110011100000111 2016120520371234567  ok

Sorry, forget my last comment, I thought this answer was to another challenge :/ The answer is perfectly valid :)

Turing Machine Code, 272 bytes
(Using, as usual, the morphett.info rule table syntax)
0 * * l B
B * * l C
C * 0 r D
D * * r E
E * * r A
A _ * l 1
A * * r *
1 0 1 l 1
1 1 0 l 2
1 _ * r Y
Y * * * X
X * _ r X
X _ _ * halt
2 * * l 2
2 _ _ l 3
3 * 1 r 4
3 1 2 r 4
3 2 3 r 4
3 3 4 r 4
3 4 5 r 4
3 5 6 r 4
3 6 7 r 4
3 7 8 r 4
3 8 9 r 4
3 9 0 l 3
4 * * r 4
4 _ _ r A

AKA "Yet another trivial modification of my earlier base converter programs."
Try it online, or you can also use test it using this java implementation.

Befunge, 20 18 bytes
Input must be terminated with EOF rather than EOL (this lets us save a couple of bytes)
>+~:0`v
^*2\%2_$.@

Try it online!
Explanation
>             The stack is initially empty, the equivalent of all zeros.
 +            So the first pass add just leaves zero as the current total.
  ~           Read a character from stdin to the top of the stack.
   :0`        Test if greater than 0 (i.e. not EOF)
      _       If true (i.e > 0) go left.
    %2        Modulo 2 is a shortcut for converting the character to a numeric value.
   \          Swap to bring the current total to the top of the stack.
 *2           Multiply the total by 2.
^             Return to the beginning of the loop,
 +            This time around add the new digit to the total.

                ...on EOF we go right...
       $      Drop the EOF character from the stack.
        .     Output the calculated total.
         @    Exit.

I had like a 60-something byte code that was dealing with integers, and wow, this is so much more simple and elegant. Great job, and nice explanation too.

Ruby, 37 bytes
ruby -e 'o=0;gets.each_byte{|i|o+=o+i%2};p o/2'
         1234567890123456789012345678901234567

This depends on the terminating \n (ASCII decimal 10) being zero modulo 2 (and on ASCII 0 and 1 being 0 and 1 mod two, respectively, which thankfully they are).

아희(Aheui), 40 bytes
아빟뱐썩러숙
뎌반뗘희멍파퍄

Accepts a string composed of 1s and 0s.
To try online
Since the online Aheui interpreter does not allow arbitrary-length strings as inputs, this alternative code must be used (identical code with slight modifications):
Add the character 벟 at the end of the first line (after 우) length(n)-times.
어우
우어
뱐썩러숙
번댜펴퍼망희땨

If the input is 10110, the first line would be 어우벟벟벟벟벟.
When prompted for an input, do NOT type quotation marks. (i.e. type 10110, not "10110")
Try it here! (copy and paste the code)

ClojureScript, 36 bytes
(fn[x](reduce #(+(* 2 %)(int %2))x))

or
#(reduce(fn[a n](+(* 2 a)(int n)))%)

The straightforward reduction.  Takes a string as input.

Minkolang v0.15, 23 19 bytes
n6ZrI[2%2i;*1R]$+N.

Try it online!
Explanation
n                             gets input in the form of a number
 6Z                           converts to string (so that it is split into an array)
   r                          reverses it
    I                         gets the stack length
     [        ]               for loop with the stack's length as the number of iterations
      2%                       gets the modulo of the ascii value
                               1 =(string conversion)> 49 =(after modulo)> 1
                               0 =(string conversion)> 48 =(after modulo)> 0
        2i;                    raises 2 to the power of the loop counter
           *                   multiplies it by the modulo
            1R                 rotates stack 1 time
              $+              sums everything
                N.            outputs as number and exit

Common Lisp, 99 88 72 bytes
Takes a string as input
(defun f(s)(reduce(lambda(a d)(+ d(* a 2)))(map'list #'digit-char-p s)))

Ungolfed:
(defun bin-to-dec (bin-str)
  (reduce (lambda (acc digit) (+ digit (* acc 2)))
          (map 'list #'digit-char-p bin-str)))

><> (Fish) 36 28 bytes
/i:1+?!v$2*$2%+!| !
/0| ;n~<

Edit 1: Forgot to put the output in the original. Added output and used MOD 2 instead of minus 48 to convert ascii to decimal to save the extra bytes lost. (no change in bytes)
Edit 2: Changed the algorithm completely. Each loop now does this; times current value by 2, then add the mod of the input. (saving of 8 bytes)
Online version
Try it Online! - This works with bigger numbers than the above link.

C, 44 bytes
d(s,v)char*s;{return*s?d(s,v+=v+*s++-48):v;}

Use as follows :
int main(){
  printf("%i\n", d("101010",0));
}

Remove two bytes and an unused parameter thanks to Steadybox

You have an unused parameter c there. Removing it saves two bytes.

SmileBASIC, 47 44 bytes
INPUT B$WHILE""<B$N=N*2+VAL(SHIFT(B$))WEND?N

Another program of the same size:
INPUT B$WHILE""<B$N=N*2OR"0"<SHIFT(B$)WEND?N

APL(NARS), 26 chars, 52 bytes
{+/a×⌽1,2x*⍳¯1+≢a←1-⍨⎕D⍳⍵}

test:
  f←{+/a×⌽1,2x*⍳¯1+≢a←1-⍨⎕D⍳⍵}
  ⎕fmt f"0"
0
~
  f"1"
1
  ⎕fmt f"101010"
42
~~
  f"10"
2
  (≢,f)"11011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
152 4995366924470859583704000893073232977339613183

152 bits... It should be limited from memory for store string and numbers.

Pip, 17 14 bytes
$+(**_*BMERVa)

Doesn't work on TIO because unary ** is only in the latest Pip version.

Try it online!

Following my own tips, Isee.

That's 2 of the 3 bytes I saw, and unary ** is another I wasn't including, but there's still one more. (It's one of my tips.) Also, BMER doesn't work because it scans as BM ER not B ME R.

can't seem to find it yet lol

Perl 5, 18 + 1 (-p) = 19 bytes
Combines techniques from the other Perl entries.  Scored using the rules at the time of posting.
s/./$\+=$\+$&/ge}{

Try it online!

JavaScript (V8), 28 26 bytes
-2 bytes thank to l4m2!
f=n=>n%2|(n<2?0:2*f(n/10))

Try it online!
Takes input as a Number, outputs a Number.

https://tio.run/##y0osSyxOLsosKNEts/j/P802z9YuT9WoRiPPxsjewMpIK00jT9/QQFPzf0FRZl6JRpoGkM0FYxsis1EkUGXQeKh8KABaAQA

ARM Thumb-2 machine code, 16 bytes
2100 f810 2b01 b112 0852 4149 e7f9 4770

Commented assembly:
        .syntax unified
        .arch armv6t2
        .thumb
        .globl bin2int
        .thumb_func
        // Input: null terminated string in r0
        // Output: integer in r1
bin2int:
        // Set initial result to zero
        movs    r1, #0
.Lloop:
        // Load char from r0 into r2, increment
        ldrb    r2, [r0], #1
        // Was it '\0'? If so, bail.
        cbz     r2, .Lend
        // Shift the lowest bit into the carry flag
        // ASCII '0' has the lowest bit clear, ASCII '1'
        // does not.
        lsrs    r2, r2, #1
        // Multiply the result by 2 (by adding to itself),
        // and add the carry flag to that result
        adcs    r1, r1
        // Jump back to .Lloop (our loop condition is cbz)
        b       .Lloop
.Lend:
        // Return
        bx      lr

The input is a null terminated string in r0 and the output is in r1.
I came up with the same idea as 640KB (SHR/ADC, or in my case, lsrs/adcs) without even seeing their solution.
Great minds think alike, I guess.

Husk, 5 bytes
Fo+Dd

Try it online!
F        # Fold from left
         # (apply binary function to each element,
         # together with the value of the previous result)
    d    # over all the digits of the input,
         # with this function:
 o       # o = combination of 2 functions
  +      # add second argument (each new digit, from left) to
   D     # double the first argument (previous result)

FunStack alpha, 31 bytes
Plus Double compose foldl1 Odd?

Takes a string consisting of 0s and 1s, outputs an integer. Try it at Replit: pass the input string as a command-line argument (formatted like \"1101\") and enter the program on stdin.
Explanation
Same idea as Steffan's Elm answer, Dominic van Essen's Husk answer, etc.
Plus Double compose

Push the functions Plus (dyadic, adds its arguments) and Double (monadic, doubles its argument. Compose them, resulting in a dyadic function that doubles its first argument and adds the result to its second argument.
foldl1

Perform a left fold over a list using that function, with the first element of the list serving as the initial accumulator value. This errors if the list is empty, but we don't have to worry about that since the input represents a positive integer.
Odd?

The list that we want to fold over is the program argument (a string, aka list of characters) with the character '0' turned into the number 0 and similarly for '1' and 1. The obvious way to do this is Minus '0', but since we only have to deal with 0 and 1, we can use Odd? instead. This function returns 1 if its argument is odd and 0 if it is even; when applied to characters, it considers whether the charcode is odd or even.

Another 31-byte answer is possible using a different approach:
Sum Times Pow 2 #N Reverse Odd?

This generates an infinite list of powers of 2, multiplies it by the input digits reversed, and sums the result.

Go, 70 bytes
func(s string)(o uint64){for _,r:=range s{o=2*o+uint64(r-'0')}
return}

Attempt This Online!
Takes in a string of binary digits (01). For each digit, convert it to it's corresponding number, and add it to twice the total.

r-'0' -> r&1

Arturo, 31 bytes
f:$[n][(n>0)?[+2*f n/10n%2]->0]

Try it

Excel, 51 48 bytes
=NPV(-0.5,MID(n,SORT(SEQUENCE(LEN(n)),,-1),1)/2)

Input n

Desmos, 51 bytes
f(n)=∑_{i=0}^{log(n+0^n)}2^imod(floor(n/10^i),10)

Try It On Desmos!
Try It On Desmos! - Prettified
Without the ban on binary list input, this could be 33 bytes:
f(l)=total(2^{[l.length-1...0]}l)

Try It On Desmos!
Try It On Desmos! - Prettified

Thunno 2 S, 4 bytes
drVO

Attempt This Online!
Explanation
drVO  # Implicit input  -> 101010
d     # Cast to digits  -> [1, 0, 1, 0, 1, 0]
 r    # Reverse         -> [0, 1, 0, 1, 0, 1]
  V   # Truthy indices  -> [1, 3, 5]
   O  # Two power       -> [2, 8, 32]
      # S flag sums     -> 42
      # Implicit output

Old:
dŻrO×  # Implicit input  -> 101010
d      # Cast to digits  -> [1, 0, 1, 0, 1, 0]
 Ż     # Length range    -> [1, 0, 1, 0, 1, 0]  [0, 1, 2, 3, 4, 5]
  r    # Reverse         -> [1, 0, 1, 0, 1, 0]  [5, 4, 3, 2, 1, 0]
   O   # Two power       -> [1, 0, 1, 0, 1, 0]  [32, 16, 8, 4, 2, 1]
    ×  # Multiply        -> [32, 0, 8, 0, 2, 0]
       # S flag sums     -> 42
       # Implicit output

Commodore C64 BASIC, 84 BASIC Bytes
0inputa$:b=len(a$):ifb=.thenend
1t=.:c=t:forx=bto1step-1:c=c+1:t=t+val(mid$(a$,c,1))*2^(x-1):next:?t

How it works
Firstly, the inputa$ is expecting the user to enter a string, though the only sanity check is that there is something is entered. We then initialise three variables, b to the string length, t to zero (in the Commodore BASIC interpreter, parsing . is slightly quicker than parsing 0), and c also to zero. As we enter the loop, we read each position from right to left.
For each position, the value in c is incremented by 1, and t adds the value of each position multiplied by 2 the power of the current bit position minus 1, and it continues until each position is calculated. The result is then printed.

Pyke, 10 9 bytes
1QY_%0m@s

Try it here!
 QY_      -    reverse digits input
1   %     -   get indecies with a value of 1
     0m@  -  map(set_nth_bit(0, i), ^)
        s - sum(^)

Also 9 bytes
Y_'XltV}+

Try it here!
Y_        - reverse digits
  'Xlt    - splat(^), len(^)-1
      V   - repeat length times:
       }+ -  double and add to stack

Jelly, 10 bytes
DLḶ2*U,DPS

You know your Jelly code is still golfable when it's above 7 bytes...
It basically consists of two parts
   2*       generate a list of the powers of two
 LḶ         for all the powers of 2 from 0 to the length of the binary input
D           Convert the binary string into a list to get its length with L
     U      Then upend that list (for '101010', we now have a list of [32, 16, 8, 4, 2, 1]
      ,     Combine this list
       D    with the individual digits of the input
        P   multiply them with eah other [32*1, 16*0, 8*1, 4*0, 2*1, 1*0]
         S  And sum the result      42 =   32 +  0  +  8 +  0 +  2 +  0

Try it online!

Mathematica, 44 bytes
2^Range[Length[d=IntegerDigits@#]-1,0,-1].d&

Unnamed function taking an integer argument (interpreted as a base-10 integer, but will only have the digits 0 and 1) and returning an integer. d is set equal to the set of digits, and then the dot product of d with the appropriate sequence of powers of 2 generates the value.

"You are not allowed to use any builtin base conversion functions." I'd consider IntegerDigits one of those.

@MartinEnder I think he's using IntegerDigits just to split all the digits in the input. The conversion part is done by 2^Range[...].d

In any case, JHM's answer is way better than mine :) so let's contemplate the use of IntegerDigits over there. If it's disallowed, JHM and I will presumably use the same string-based preprocessing step, and the other answer will still be better!

JavaScript, 35 bytes
f=([c,...b],n=0)=>c<2?f(b,+c+n+n):n

For c='1' and c='0', c<2 returns true.
If b is empty, c will be undefined in the next recursion and c<2 will be false.

Hehe ... the 35th answer has 35 bytes. :)

Julia 0.5, 22 bytes
!n=n>0&&2*!(n÷10)|n&1

Try it online!

Keg, -rr,  14 12 bytes
0&÷^⑷2⑻Ë*⑹⑸⅀

Try it online!
Explained
0&              # Place 0 into the register. This will serve as the power to which 2 will be raised
  ÷^            # Take the input as a number and split it into it's individual numbers. It is then reversed.
    ⑷           # Start a map applying the following to each item in the input:
      2⑻Ë*      #   Exponate 2 to the power of the register and multiply the number by that value
          ⑹     #   Increment the register
           ⑸⅀  # Close the map and sum the stack, printing that sum implicitly

Japt -x, 6 bytes
Ô¬ËÑpE

Try it

Stax, 4 bytes
╖~♫p

Run and debug it
same reducing idea as Jelly.

Raku, 33 bytes
{.flip.comb.kv.map(2*** * *).sum}

(If builtins were allowed, this would just be .parse-base(2).)
Explanation:
.flip reverses the string, .comb converts it into a list of chars, .kv inserts the index of each char in front of it. The map block consumes two elements at a time, computing the product of 2 to the power of the first argument (the index) all multiplied by the second argument (the 0 or 1), and the resulting list of products is totaled by .sum.
The asterisks in the map call are doing triple duty: the first two are the exponentiation operator, while the third is a Whatever standing for the first argument to the block (and is the reason the expression becomes a block without curlies). Likewise, the fourth is the standard ASCII multiplication operator, while the fifth is another Whatever representing the second argument. So this ungolfed version does the same thing:
… .map( { 2**$^k × $^v } ) …

Try it online!

shell with dc, 16 13 10 bytes
There's already a bash + GNU utils, but this solution is POSIX compliant and shorter.
dc -e "10o2i$1p"

It's also a bit quicker (we use internal functioning instead of extra computation, plus there's only one process call instead of two.) But, quoting and extra spaces aren't mandatory
dc -e10o2i$1p

Now, explanation of the expression (-e argument)

10 o ask to set Output base to decimal.
2 i ask to set Input base to binary.
Note that the order matters here.
If we issue first 2i, 10o would be read as request to set to binary…
$1 p ask to Print out the entry…
Read then as binary and expressed in decimal form.

Better, on standard installations with no DC_ENV_ARGS or others (depending your implementation) variable set, default base is decimal. So, finally
dc -e2i$1p

Note : dc is a big bases-converter where i tells how to parse inputs (kinda scanf()) and o tells how to display it (kinda printf()). Values are always stored and manipulated using DCB representation.

But the instructions say “You are not allowed to use any builtin base conversion functions.”

So the whole command should be discard (in bash answer too): the command is a base conversion itself, but it's not a shell builtin.

It’s not a big deal to me one way or another but I think the point is to do the math operations explicitly.  They don’t mention the shell at all, just “builtin” which I assume refers to built in functionality to perform these math operations.  Maybe ask for clarification.

"the point is to do the math operations explicitly." That's a better mention than "You are not allowed to use any builtin base conversion functions." because I just avoid the shell stuff $((2#$1)) and even for dc external command, the i function is a kinda "Integer-to-decimal functions" :s

I may be misreading it, but that's how I understood it.

TI-Basic, 29 bytes
sum(seq(sub(Ans,length(Ans)-I,1)2^I,I,0,length(Ans)-1

Takes input as a string in Ans.

Java 8, 54 bytes
Solution using Streams only :
s->s.chars().mapToLong(e->e).reduce(0,(a,b)->2*a+b-48)

Try it online!

If the question didn't require a long, the answer could have been shorter and more elegant (38 bytes) :
s->s.chars().reduce(0,(a,b)->2*a+b-48)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes