From 530daaf8210d2be0b316fa78a43fd74519036047 Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 15 Aug 2018 20:28:22 -0700 Subject: [PATCH] Completed BinaryAndDecimal --- lib/binary_to_decimal.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 439e8c6..1c7e41b 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -4,6 +4,14 @@ # The least significant bit is at index 7. # Calculate and return the decimal value for this binary number using # the algorithm you devised in class. + def binary_to_decimal(binary_array) - raise NotImplementedError + binary_digit = 128 + total = 0 + binary_array.each do |num| + num *= binary_digit + total += num + binary_digit = binary_digit / 2 + end + return total end