Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
int i = int.Parse(s, System.Globalization.NumberStyles.BinaryNumber);
erlang:list_to_integer(S,2).
character (len=:), allocatable :: s
integer :: i
s = '1101'
read (s,'(B4)') i
The B4 format means a string of length 4. The length of the field could be adjusted by constructing the format field on the fly with an internal write.
const i = parseInt(s, 2)
Integer i = Integer.valueOf(s, 2);
The second argument in the valueOf method denotes the radix, or base, of the said value.
int i = s.chars()
.map(x -> x - '0')
.reduce(0, (a, b) -> a * 2 + b);
$i = bindec($s);
i = 0
for x in map(int, s):
i = i * 2 + x
i = int(s, 2)