Binary is a numer system used by computers
Binary is a numer system used by computers. It consists of only two digits, 0 and 1, which
represent off and on. In decimal numbers, there are ten digits, 0 to 9. When you write 247 in decimal, it represents(2 x 10^2)+(4 x 10^1)+(7 x 10^0).The same is true in binary, only the base number is ***** instead of ten. Thus, 1101 is (1 x 2^3)+(1 x 2^2)+(0 x 2^1)+(1 x 2^0).
You can convert an integer decimal number to binary number by a recursive algorithm.
Binary(x)
simple cases: If X is 0, the binary of X is 0. If X is 1, the binary of X is 1.
Complex case: Print the binary of (X / 2). Print the binary of (X%2).(Note:% means the remainder of a division.)
Test your function: The binary of 12 is 1100. The binary of 3 is 11.
Hint: Do not use floating point numbers. This algorithm only works with integer numbers.
10 years ago
Purchase the answer to view it

- recursivebinary.zip