Function ascii_converter::binary_to_decimal
source · [−]Expand description
This function takes in binary numbers and will return the decimal version.
This function takes a Vec<u8>
, it’s elements should represent binary values.
if a value passed in contains a digit that isn’t 1
or 0
an error will be thrown.
Example
use ascii_converter::*;
let hello_world = vec![1001000, 1100101, 1101100, 1101100, 1101111, 100000, 1110111, 1101111, 1110010, 1101100, 1100100, 100001];
let expected = vec![72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33];
assert_eq!(binary_to_decimal(&hello_world).unwrap(), expected);