how to write a psuedocode for the conversion of decimal to binary numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to write a psuedocode for the conversion of decimal to binary numbers?

17th Sep 2017, 8:40 AM
kamran arshad
kamran arshad - avatar
4 Answers
+ 4
I doesn't know what kind of 'pseudocode' you are expecting, but in human words: D is the value (integer -- decimal is no sense, as decimal is only a number representation) to convert to binary S is an empty string to store the binary representation of D do: + add remainder of D integer divided by 2 at start of S + integer divide D by 2 while D is greater than zero ... same algorithm for any base, replacing 2 by the required base (remainder of and divide by 10 for decimal, by 8 for octal, or 16 for hexadecimal -- for bases greater than 10, output string need to be build using letters for representation of digits greater than 9 ^^)
17th Sep 2017, 1:35 PM
visph
visph - avatar
+ 4
In JS it's no more 'pseudocode', but real one... and you certainly can do it by yourself ^^ var D = prompt('enter an integer'); var S = ''; do { S = (D%2)+S; D /= 2; } while (D>0); alert(S);
17th Sep 2017, 1:55 PM
visph
visph - avatar
0
Thank you can you do it using while loop in javascript
17th Sep 2017, 1:44 PM
kamran arshad
kamran arshad - avatar
0
thank u
18th Sep 2017, 2:53 PM
kamran arshad
kamran arshad - avatar