15,792,338 members
1.00/5 (1 vote)
See more:
How I can convert from decimal to binary in c++ ?
Posted
Matthew Faithfull 16-Mar-13 18:19pm
You're going to have to be a little more specific. Any number used in C++, decimal or otherwise is already being represented in binary to exist on a binary computer in the first place so no conversion as such is necessary. Do you want a std::string with the 1's and 0's in or something else?
Captain Price 17-Mar-13 8:02am
my 5
Sergey Alexandrovich Kryukov 19-Mar-13 22:07pm
Despite two answers, I still don't understand the question. A number cannot be "decimal" or "binary". Everything is binary. "Decimal" can only be a string.
So, you might ask about string representation of some numeric value, such as "1010101100010". You should understand that this is a string.
—SA

## Solution 2

I searched using search text: convert decimal to binary string, I found a couple examples that should give you some help to write your conversion program.

Using .NET Framework method
Convert.ToString Method (Int16, Int32)[^]
```int number=63;
Console.WriteLine(Convert.ToString(number, 2)); // Convert number to Base 2 string```

Using an algorithm
How to Convert a Decimal Number to a Binary Number in a String[^]. You'll have to convert the syntax from VB to C++.
Decimal to Binary Example Program[^]
Decimal to Binary Source Code[^]. A previously answered CodeProject.com question. See Solution 1.

v5

## Solution 1

Works well for me right now, so I'll share: Decimal to Binary.

Regards,
— Manfred