954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Managed C++ : Int to String representation of Binary

Hi all,

I'm trying to create a method in managed c++ which will convert an int to a string representation of binary.

I have done this in C# before, but I can't work out how to do it in Managed C++

Below is the code from my C# effort that worked.

Scott

// This is C# Code

public string intToBinary(int convertThis)
        {
            string converted = Convert.ToString(convertThis, 2);
            return converted;

        }
Smithy566
Newbie Poster
12 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

You can use "atoi" to convert a string to int and "itoa" to convert it from int to string, or the other way around xD.

Look for it on MSDN

Pynolathgeen
Light Poster
41 posts since Mar 2010
Reputation Points: 29
Solved Threads: 3
 

Use this in managed c++ to get the binary string representation of an integer value
If value = 126 the method will return "1111110"

public:
String^ IntToBinaryString (int value)
{
 String^ result = Convert::ToString(value, 2);
 return result;
 // Or just 
 // return Convert::ToString(value, 2);
}
Milton Neal
Light Poster
43 posts since Sep 2010
Reputation Points: 10
Solved Threads: 9
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: