Question: In a computer system, integers are represented as a sequence of binary bits of 0 or 1. Binary is a base-2 number system instead of

In a computer system, integers are represented as a sequence of binary bits of 0 or 1. Binary is a base-2 number system instead of the decimal (base10) system we are familiar with. Write a program which calls a recursive function PrintBinary(int num) that prints the binary representation for a given decimal integer. For example, calling PrintBinary(7) would print 111. Your function may assume the integer parameter is non-negative. The following Figure shows an algorithm for the conversion from a decimal number to a binary number. First, write the decimal number as the dividend and "2" as the divisor. Write the integer answer (quotient) under the long division symbol, and write the remainder (0 or 1) to the right of the dividend. Continue downwards, dividing each new quotient by two and writing the remainders to the right of each dividend, until when the quotient is 0. You will get the binary number by reading the sequence of remainders upwards to the top (starting with the bottom remainder). One hint to this problem is that you need to work backwards. There is a straightforward way to easily identify and print the last binary digit, but you need to print that digit only after you have printed all the other binary digits.

2156 Remainder 278 2)39 219 29 24 0 0 0 0 21 156 10E 100111002

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!