Write a program to output the binary representation


Discuss the below:

Q: Write a C++ program to output the binary (base-2) representation of a decimal integer. The algorithm for this conversion is to be repeated dividing the decimal number by 2 until it is 0. Each division produces a remainder of 0 or 1 which becomes a digit in the binary numbers.

example the decimal number 25

25/2 = 12 remainder 1
12/2 = 6 remainder 0
6/2 = 3 remainder 0
3/2 - 1 remainder 1
1/2 = 0 remainder 1

 

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write a program to output the binary representation
Reference No:- TGS01937615

Now Priced at $20 (50% Discount)

Recommended (93%)

Rated (4.5/5)