-
Make variables called:
original
and set its value to the input number given by the end user.decimal_value
and set its value tooriginal
(this is so we can still use the original number later)bit_value
and set its value to 1. Find the smallest bit value which is larger than thedecimal_number
by doubling value ofbit_value
while it is smaller or equal todecimal_number
.binary_number
is a string variable and stores the binary cards needed (‘1’ for dots showing and ‘0’ for not showing).
-
Set the variable
bit_value
to 1 and find the smallestbit_value
which is larger thandecimal_number
by multiplyingbit_value
by 2 while it is smaller or equal todecimal_number
. You can do this by using a while loop. -
Now divide the
bit_value
by 2 and check ifdecimal_number
is greater than or equal tobit_value
. If it is, add ‘1’ to the stringbinary_number
and subtractbit_value
fromdecimal_number
. If not, add ‘0’ to the stringbinary_number
. Repeat whilebit_value
is greater than 1. Display the value ofbinary_number
as the output.