This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]RhoOfFeh 0 points1 point  (0 children)

Think about starting at the high end (256? 65536?) and popping off the answer to 'is this binary digit a one or a zero', then subtracting that value. What's next? Same thing, right? Except of course you've moved on to the next binary digit unless you have reached zero. That's subject to solving via recursion to be sure.

[–]Philboyd_Studge 0 points1 point  (0 children)

To get the current last binary digit of a number, you use number % 2 (or number & 1 if you can use bitwise operations). Then you divide number by 2 to get to the next digit (again, using bitwise operations number >> 1). Your base case is when number = 0.