Member Avatar for Smithy566

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.


// This is C# Code

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


Recommended Answers

All 2 Replies

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

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

String^ IntToBinaryString (int value)
 String^ result = Convert::ToString(value, 2);
 return result;
 // Or just 
 // return Convert::ToString(value, 2);
commented: Excellent, just what I needed +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.