# Write a C++ program to output the binary

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 Summary

Write a C++ program to output the binary (base-2) representation of a decimal integer.

\$2.19
###### This answer includes:
• Plain text
• Cited sources when necessary
• Attached file(s)
• 130836.cpp
Add to Cart   \$2.19

Yupei Xiong, PhD

Rating 4.8/5

Active since 1969

BSc, Peking University
MA, Peking University
PhD, University of Maryland - College Park Campus

Responses 4195

Comments on Yupei's work:

"thaaaaaaaaanx very much.. but you write(* public static double readGrade(Scanner scanner, String prompt) { what did u mean from that.?!"

"Thank you for the explanations. I have a better understanding of these problems and how to solve them"

"Thank you! u=sqrt(x) >0 was really a great reasoning. Thanks!"

"Can you check question# 8-13-15-18-19 for me, I just want to make sure... because Im different type of errors Thank you!"

"Did you have these codes before or you just created them this morning?"