diff --git a/binary_to_decimal.rb b/binary_to_decimal.rb new file mode 100644 index 0000000..154249b --- /dev/null +++ b/binary_to_decimal.rb @@ -0,0 +1,9 @@ +def binary_to_decimal(binary_array) #[01010100] 2**7 ~ 2**0 + sum = 0 + length = 8 + binary_array.each do |i| + length -= 1 + sum += i.to_i * (2**length) + end + sum +end