Created
November 30, 2018 20:32
-
-
Save iagox86/146f8426425a10eb882126b49152e98d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn from_binary(s: &str) -> Option<u32> { | |
let total: u32 = s.chars().rev().enumerate().map(|c| { | |
let (i, c) = c; | |
if c == '1' { | |
(2 as u32).pow(i as u32) | |
} else { | |
0 | |
} | |
}).sum(); | |
return Some(total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment