Click here to Skip to main content
Rate this: bad
good
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 3:21am

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 420
1 CHill60 410
2 Sergey Alexandrovich Kryukov 384
3 PIEBALDconsult 235
4 BillWoodruff 190


Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
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