diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..8bf4d45 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/binary-and-decimal.iml b/.idea/binary-and-decimal.iml new file mode 100644 index 0000000..652a340 --- /dev/null +++ b/.idea/binary-and-decimal.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b0db9b0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..15ffe97 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d7f43dc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 59df67b..a81a744 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -ruby '2.6.6' +#ruby '2.6.6' 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 diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 439e8c6..a54fd66 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -5,5 +5,17 @@ # 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 + #raise NotImplementedError + decimal_number = 0 + exponent = 7 + + binary_array.each do |element| + decimal_number += element * 2** exponent + exponent += -1 + end + + decimal_number + end + +p binary_to_decimal([1,1,0,1,0,0,1]) \ No newline at end of file