From e6961427dd2f1a39daf592ab6b4dbd4f00d707e7 Mon Sep 17 00:00:00 2001 From: Mary Lamkin Date: Sat, 24 Feb 2018 12:59:19 -0800 Subject: [PATCH] adds method for binary to decimal. tests pass. --- lib/binary_to_decimal.rb | 3 +++ specs/binary_to_decimal_spec.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 439e8c6..c09e14e 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -5,5 +5,8 @@ # Calculate and return the decimal value for this binary number using # the algorithm you devised in class. def binary_to_decimal(binary_array) + decimal = binary_array[7] + (binary_array[6] * 2) + (binary_array[5] * 4) + (binary_array[4] * 8) + (binary_array[3] * 16) + (binary_array[2] * 32) + (binary_array[1] * 64) + (binary_array[0] * 128) + + return decimal raise NotImplementedError end diff --git a/specs/binary_to_decimal_spec.rb b/specs/binary_to_decimal_spec.rb index ba17713..0da4e51 100644 --- a/specs/binary_to_decimal_spec.rb +++ b/specs/binary_to_decimal_spec.rb @@ -2,6 +2,8 @@ require 'minitest/reporters' require_relative '../lib/binary_to_decimal' + + describe "binary to decimal" do it "From 10011001 to 153" do binary_array = [1, 0, 0, 1, 1, 0, 0, 1]