-
Make variables called:
originaland set its value to the input number given by the end user.numberand set its value tooriginal(so we can useoriginallater)bit_valueand set its value to 1. Find the smallest bit value which is larger than thenumberby doubling value ofbit_valuewhile it is smaller than or equal tonumber.cardsis a string variable and stores the binary cards needed (‘B’ for black cards and ‘W’ for white cards).
-
Set the variable
bit_valueto 1 and find the smallestbit_valuewhich is larger thannumberby multiplyingbit_valueby 2 while it is smaller than or equal tonumber. You can do this by using a while loop. -
Now divide the
bit_valueby 2 and check ifnumberis greater than or equal tobit_value. If it is, add ‘W’ to string variablecardsand subtractbit_valuefrom thenumber. If not, add ‘B’ to string variablecards. Repeat whilebit_valueis greater than 1. Display the value ofcardsas the output. -
Test your program with some values on the boundaries (for example test it with numbers 255 and 256).