answersLogoWhite

0

I am assuming you mean positive integer in decimal notation.

Here is an algorithm that lists the binary representation backwards, that is

from right to left, least significant digit first.

N is the number decimal number

While N > 0

print N rem 2 // output the remainder

N = N/2 // replace N by n divided by 2

end loop

Example: trace for n = 101

n output

101

50 1

25 0

12 1

6 0

3 0

1 1 -- Last one had 0; 3%2 is 1

0 1

Output would be 1010011 ---- from left to right would be 1100101

Check: 64 + 32 + 0 + 0 + 4 + 1 = 101.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
RossRoss
Every question is just a happy little opportunity.
Chat with Ross

Add your answer:

Earn +20 pts
Q: Algorithm for finding binary representation of positive decimal integer?
Write your answer...
Submit
Still have questions?
magnify glass
imp