Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #251 Parse binary digits

Extract integer value i from its binary string representation s (in radix 2)
E.g. "1101" -> 13

i = s.to_i(2)

The 2 can be any radix up to 36.
(def i (read-string (str "2r" s)))

New implementation...