Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Test #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
41 changes: 41 additions & 0 deletions Terminal Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Last login: Sun Aug 19 15:48:20 on ttys003
Sabines-MacBook-Pro:~ ada$ ls
Applications Music git-sandbox
Desktop Pictures hello.rb
Documents Public pryme.rb
Downloads ada tdd-exercise
Library clock
Movies git-pull-activity
Sabines-MacBook-Pro:~ ada$ cd Documents
Sabines-MacBook-Pro:Documents ada$ ls
Ruby_wk.1 Ruby_wk.2 Ruby_wk.3 friendship_note jump-start-live
Sabines-MacBook-Pro:Documents ada$ cd CS_fundamentals_wk.3
-bash: cd: CS_fundamentals_wk.3: No such file or directory
Sabines-MacBook-Pro:Documents ada$ mkdir CS_fundamentals_wk.3
Sabines-MacBook-Pro:Documents ada$ ls
CS_fundamentals_wk.3 Ruby_wk.2 friendship_note
Ruby_wk.1 Ruby_wk.3 jump-start-live
Sabines-MacBook-Pro:Documents ada$ cd CS_fundamentals_wk.3/
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ git clone https://github.com/Sabineth17/array_equals.git
Cloning into 'array_equals'...
remote: Counting objects: 15, done.
remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15
Unpacking objects: 100% (15/15), done.
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ atom .
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ cd CS_fundamentals_wk.3
-bash: cd: CS_fundamentals_wk.3: No such file or directory
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ ls
array_equals
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ git clone https://github.com/Sabineth17/BinaryAndDecimal.git
Cloning into 'BinaryAndDecimal'...
remote: Counting objects: 42, done.
remote: Total 42 (delta 0), reused 0 (delta 0), pack-reused 42
Unpacking objects: 100% (42/42), done.
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ atom .
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ ls
BinaryAndDecimal array_equals
Sabines-MacBook-Pro:CS_fundamentals_wk.3 ada$ cd BinaryAndDecimal/
Sabines-MacBook-Pro:BinaryAndDecimal ada$ ls
README.md lib rakefile specs
Sabines-MacBook-Pro:BinaryAndDecimal ada$ atom .
Sabines-MacBook-Pro:BinaryAndDecimal ada$
19 changes: 18 additions & 1 deletion lib/binary_to_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
# 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)
# binary_array[0] = "" * (2**7)
# binary_array[7] = "" * (2**0)
# # raise NotImplementedError
# end
#
# binary_array = Array.new(8) { rand(0..1) }

def binary_to_decimal(binary_array)
raise NotImplementedError
sum = 0
8.times do |index|
if binary_array[index] == 1
sum += (2 ** (7 - index))
end
end
return sum
end