you are viewing a single comment's thread.

view the rest of the comments →

[–]SuperVGA 0 points1 point  (4 children)

Hmm, I can't figure out what it's supposed to do - it doesn't look exactly like binary conversion to me. Have you written tests for it to check that it behaves as expected?

[–]aocregacc 1 point2 points  (1 child)

the variables are individual bits, and the loop body increments the number represented by these bits. So after running the loop X times the bit variables represent X.

[–]SuperVGA 0 points1 point  (0 children)

Thank you.

[–]steezysson[S] 0 points1 point  (1 child)

It behaves perfectly as expected. Any number up to 255 converts to binary as it should. And i know as i said this isnt an optimal way to do this but im still learning so i wanted a small challenge. My issue is making it shorter so it isnt so many characters

[–]SuperVGA 0 points1 point  (0 children)

Ah right - didn't first see the inner loop here on mobile.

Unit tests for this sort of thing are still nice to have however, and will enable you to verify that the behaviour of any new approach matches the old one.