0

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;

        }
3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Milton Neal
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

1

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);
}
Votes + Comments
Excellent, just what I needed
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.