Skip to content

Conversation

@KateAnnNichols
Copy link

Binary and Decimal

Congratulations! You're submitting your assignment.

def binary_to_decimal(binary_array)
raise NotImplementedError
decimal = 0
8.times do |i|

Choose a reason for hiding this comment

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

Good job with the do ... loop. Can you think of a way to generalize the algorithm so that it works for n bits?

raise NotImplementedError
decimal = 0
8.times do |i|
decimal += binary_array[i] * 2 ** (7 - i)

Choose a reason for hiding this comment

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

Good job with using the math operator **. Can you think of a faster way to perform this without having to use the ** operation? Your code currently requires recalculating 2 to the power of n (number of bits) at every iteration.

@shrutivanw
Copy link
Collaborator

Nice work!

Think about the comments and questions that your code review buddy shared with you, and discuss them further with your buddy.

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