Created
January 28, 2015 14:20
-
-
Save dasibre/8e3e7dd3832b3eb117bb to your computer and use it in GitHub Desktop.
Binary to Decimal
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
def bin_to_dec(str_binary) | |
base = 2 | |
results = 0 | |
size = str_binary.size | |
exponent = size - 1 | |
0.upto(exponent) do |index| | |
results += (str_binary[index].to_i * base ** exponent) | |
exponent -= 1 | |
end | |
results | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment