Skip to content

Sockets - Erica#35

Open
norrise120 wants to merge 1 commit intoAda-C11:masterfrom
norrise120:master
Open

Sockets - Erica#35
norrise120 wants to merge 1 commit intoAda-C11:masterfrom
norrise120:master

Conversation

@norrise120
Copy link
Copy Markdown

Binary and Decimal

Congratulations! You're submitting your assignment.

Comment thread lib/binary_to_decimal.rb
decimal = 0
binary_array.length.times do |i|
decimal += binary_array[i] * 2 ** (7 - i)
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall, I think your code looks great! It's very concise! One comment that I have is on line 11, in the case where you would want to scale this program to intake binary number greater than 8 numbers, you might want to modify exponent of the 2 (the 7-i part). Perhaps setting the binary_array.length = n and the exponent would be (n-i). For example if the binary_array.length = 9 then the exponent would be (9-i) Let me know if this does not make sense :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's great feedback! To address this feedback, how about leveraging the length of the array? Instead of 7, use binary_array.length - 1.

@shrutivanw
Copy link
Copy Markdown
Collaborator

Nice work! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants