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.
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