Click here to Skip to main content
15,792,338 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How I can convert from decimal to binary in c++ ?
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.

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 question. See Solution 1.
Share this answer
Google broken again? ;)

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

— Manfred
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900