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
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GEM
remote: http://rubygems.org/
specs:
ansi (1.5.0)
builder (3.2.3)
minitest (5.10.3)
minitest-reporters (1.3.8)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
minitest-skip (0.0.1)
minitest (~> 5.0)
rake (12.3.0)
ruby-progressbar (1.10.1)

PLATFORMS
ruby

DEPENDENCIES
minitest
minitest-reporters
minitest-skip
rake

RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.17.3
20 changes: 17 additions & 3 deletions lib/binary_to_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
# The array is randomly filled with 0’s and 1’s.
# The most significant bit is at index 0.
# The least significant bit is at index 7.
# Calculate and return the decimal value for this binary number using
# 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
end
bit = binary_array.length - 1
exponent = 0
decimal_result = 0

if binary_array.class != Array
raise ArgumentError
else
until bit < 0
decimal_result += binary_array[bit] * (2 ** exponent)
bit -= 1
exponent += 1
end
end

return decimal_result
end