12,296,307 members (60,211 online)
Rate this:
See more:
Please i needed to a working pseudo code for converting any binary code to its equivalent decimal representation
Posted 23-Jan-13 3:21am

Rate this:

Solution 1

It's not complex: all you need to do is use the modulus and divide operators until there is no number left:

1) Set `inp` to binary number.
2) Set `digit` to `inp` modulus 10. Output `digit`
3) Set `inp` to `inp` divided by 10
4) If `inp` is not zero, repeat from (2)

The only complication is that this generates the digits in the wrong order: least significant first. So you will need to make your "Output Digit" cope with that, and probably store them in reverse order for output at the end. Exactly how you do that isn't complex, but I don't know how far you have got in your course, so I won't suggest anything - you have probably got an idea from the lecture that this was the homework from.

Top Experts
Last 24hrsThis month
 OriginalGriff 460 Richard MacCutchan 395 Peter Leow 378 Karthik Bangalore 319 George Jonsson 175
 OriginalGriff 9,060 ppolymorphe 5,402 CHill60 5,260 Karthik Bangalore 4,791 Richard MacCutchan 4,520