Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

ruby '2.6.6'
# ruby '2.6.5'

gem 'rake'

Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ DEPENDENCIES
minitest-skip
rake

RUBY VERSION
ruby 2.6.5p114

BUNDLED WITH
2.1.4
6 changes: 6 additions & 0 deletions lib/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/.idea/lib.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lib/binary_to_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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
Comment on lines +11 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, just fixing indentation.

Suggested change
binary_array.each do |digit|
sum_of_digits += digit * (2**power_of_digit)
power_of_digit -= 1
end
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

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])