From 0bfe12528b603440be8a2690fab5495a38a62bc2 Mon Sep 17 00:00:00 2001 From: Hanh Solo Date: Thu, 10 Sep 2020 16:24:46 -0700 Subject: [PATCH 1/3] testing --- Gemfile | 2 +- Gemfile.lock | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 59df67b..a923525 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -ruby '2.6.6' +# ruby '2.6.5' gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index 4dd4a62..0d6fcce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,8 +23,5 @@ DEPENDENCIES minitest-skip rake -RUBY VERSION - ruby 2.6.5p114 - BUNDLED WITH 2.1.4 From 23818936301f6c370edee88bd3da68e668d886be Mon Sep 17 00:00:00 2001 From: Hanh Solo Date: Thu, 10 Sep 2020 16:25:38 -0700 Subject: [PATCH 2/3] testing testing 2 --- lib/binary_to_decimal.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 439e8c6..9568f34 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -7,3 +7,4 @@ def binary_to_decimal(binary_array) raise NotImplementedError end +# this iss From 181425b888223e677127a51055722554ea2fb09b Mon Sep 17 00:00:00 2001 From: Hanh Solo Date: Wed, 16 Sep 2020 13:09:17 -0700 Subject: [PATCH 3/3] binary-and-decimal submission --- lib/.idea/.gitignore | 6 ++++++ lib/.idea/inspectionProfiles/Project_Default.xml | 6 ++++++ lib/.idea/lib.iml | 15 +++++++++++++++ lib/.idea/misc.xml | 4 ++++ lib/.idea/modules.xml | 8 ++++++++ lib/.idea/vcs.xml | 6 ++++++ lib/binary_to_decimal.rb | 15 ++++++++++++++- 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/.idea/.gitignore create mode 100644 lib/.idea/inspectionProfiles/Project_Default.xml create mode 100644 lib/.idea/lib.iml create mode 100644 lib/.idea/misc.xml create mode 100644 lib/.idea/modules.xml create mode 100644 lib/.idea/vcs.xml diff --git a/lib/.idea/.gitignore b/lib/.idea/.gitignore new file mode 100644 index 0000000..8bf4d45 --- /dev/null +++ b/lib/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/lib/.idea/inspectionProfiles/Project_Default.xml b/lib/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b0db9b0 --- /dev/null +++ b/lib/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/lib/.idea/lib.iml b/lib/.idea/lib.iml new file mode 100644 index 0000000..6e7c09c --- /dev/null +++ b/lib/.idea/lib.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/.idea/misc.xml b/lib/.idea/misc.xml new file mode 100644 index 0000000..15ffe97 --- /dev/null +++ b/lib/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/lib/.idea/modules.xml b/lib/.idea/modules.xml new file mode 100644 index 0000000..b0c4ff6 --- /dev/null +++ b/lib/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lib/.idea/vcs.xml b/lib/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/lib/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 9568f34..5dd5a72 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -4,7 +4,20 @@ # 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) + sum_of_digits = 0 + power_of_digit = 7 + binary_array.each do |digit| + sum_of_digits += digit * (2**power_of_digit) + power_of_digit -= 1 + end + return sum_of_digits raise NotImplementedError end -# this iss + +puts binary_to_decimal([0, 0, 0, 0, 0, 0, 0, 0]) +puts binary_to_decimal([0, 0, 0, 0, 0, 0, 0, 1]) +puts binary_to_decimal([1, 0, 0, 0, 0, 0, 0, 1]) +puts binary_to_decimal([0, 0, 0, 0, 0, 0, 1, 1]) +