Search code examples
c++-clistring-parsing

Converting Int32 to binary in c++


I'm asking for help here after searching all around the web

I'm working on a school project, in Windows Forms, using managed C++. My problem is that I've got an Int32 value and I need to convert it to a binary value using System::Convert but I don't know how to use it properly.

I've tried doing this :

convertit = Int32::Parse(str);
static unsigned char ToByte(convertit);

Thank's for your help


Solution

  • I've found a solution. All I needed to do was

             // Binary button checked
             if(this->radioButtonBin->Checked==true)
             { 
             int nb = System::Convert::ToInt32(str, 2);
             this->textBoxClosed->Text=nb.ToString();
             }
    
             // Decimal button checked
             else
             {
             int nb = Convert::ToInt32(str, 10);
             String^ nb1 = System::Convert::ToString(nb, 2);
             this->textBoxClosed->Text=nb1;
             }