Skip to content

Conversation

@norrise120
Copy link

Binary and Decimal

Congratulations! You're submitting your assignment.

decimal = 0
binary_array.length.times do |i|
decimal += binary_array[i] * 2 ** (7 - i)
end

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