Skip to main content
1 of 4
Ravi
  • 151
  • 1
  • 1
  • 6

Algorithm to convert decimal number to binary

I am reading this material to understand the basics of number system. I am stuck at a point in that material where it writes the algorithm to convert a decimal number to binary number. The heading of that part where I am stuck is Decimal to Base The algorithm it mentions there is:

(The algorithm below I copied and pasted from there but it isn't displayed here properly, please refer the link)

(1)LetP=int(V−−√B)
(2)Letv=int(V÷BP)
(visthenextdigittotheright)
(3)MakeV=V−vBp
(4)Repeatsteps1through3untilp=0

It is explaining by taking an example of converting decimal number 236 to binary.

I am not getting how it is calculating the 1st step, i.e. to get the value of p.

It writes that p = int(square root of V)

Now, square root of 236 = 15.36229149573721635154

As per point number 1, p = integer part of 15.36229149573721635154 So, I remove the decimal part and p then becomes 15. But the material there says it is 7.

I can't get what is happening here. I am stuck.

Ravi
  • 151
  • 1
  • 1
  • 6