12,747,162 members (30,140 online)
Rate this:
See more:
hello please help me here I need to convert base 10 integer to binary coded base 2 in c++ i really don't know where to start
Posted 27-Feb-13 5:21am
Sergey Alexandrovich Kryukov 11-Apr-13 18:06pm

Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.

You already got 3 abuse report on your non-answer. You don't want it: if wrong posting start annoy people, they may report the account, which is worse. Just be careful about it.

Thank you for understanding.
—SA

Rate this:

Rate this:

## Solution 1

Break it into two steps:

1. convert base 10 integer to binary coded base 2
I hope you know (you should if you are asked to code it!) how to convert a decimal number into binary.... (Hint: Keep dividing by 2 and remainders make binary number)

2. Code the conversion step in C++
Once you are done with 1, you will see it's straight forward coding for conversion. Keep account of remainders to read all at once at end.

Try out. Post specific issue if you face any.
Rate this:

## Solution 3

Here is a C# .NET example that does it. You should be able to convert this to C++.

The bolded line below converts an integer to a string that contains the binary representation of the integer.
```int intValue = 10; // Original Integer value to be converted
string binValue = Convert.ToString(intValue, 2); // Integer value represented as a string of binary digits
int intBackToOriginalValue = Convert.ToInt32(binValue, 2); // Binary value converted to Integer
MessageBox.Show("bin: " + binValue.ToString() + Constants.vbNewLine + "int: " + intValue.ToString() + Constants.vbNewLine + "back" + intBackToOriginalValue.ToString());```

See Convert.ToString Method (Int32, Int32)[^]. The Microsoft documentation shows that Convert.ToString can be used in C++ but does not provide an example.

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 158 Graeme_Grant 130 OriginalGriff 130 Maciej Los 85 NightWizzard 80
 OriginalGriff 3,658 Peter Leow 2,751 ppolymorphe 1,983 Karthik Bangalore 1,700 Richard MacCutchan 1,329