I need to take a decimal base 10 number supplied by the user and convert it to binary. Is there an equation for this? What would the code look like?
Printable View
I need to take a decimal base 10 number supplied by the user and convert it to binary. Is there an equation for this? What would the code look like?
There's a FAQ on bitwise operators you could always read. Or you could search the forum, since this gets asked all the time.
Quzah.
With "convert" you think about printing out the binary digits? If so, look up bitwise operators and/or the modulo operator.
Just code what you do on paper.
input in decimal is x
while x is greater than 0
a is x%2
store a in char array
x is x/2
increment array index
end loop
***if your convert mean binary equivalent of decimal no.