0
how to write a psuedocode for the conversion of decimal to binary numbers?
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 ^^)
+ 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);
0
Thank you can you do it using while loop in javascript
0
thank u