Skip to content

Instantly share code, notes, and snippets.

@dasibre
Created January 28, 2015 14:20
Show Gist options
  • Save dasibre/8e3e7dd3832b3eb117bb to your computer and use it in GitHub Desktop.
Save dasibre/8e3e7dd3832b3eb117bb to your computer and use it in GitHub Desktop.
Binary to Decimal
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