Click here to Skip to main content
12,815,057 members (41,518 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
Please i needed to a working pseudo code for converting any binary code to its equivalent decimal representation
Posted 23-Jan-13 4:21am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100