Visual c++ 如何让这段代码接受65并用c++/cli
你不明白什么是二进制数字。如果需要将任何整数转换为其字符串表示,可以执行以下操作:Visual c++ 如何让这段代码接受65并用c++/cli,visual-c++,c++-cli,Visual C++,C++ Cli,你不明白什么是二进制数字。如果需要将任何整数转换为其字符串表示,可以执行以下操作: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int base10; long base2 = 0; base10 = Convert::ToInt32(txtBase10->Text); base2 = base10 / 128 * 1000000
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int base10;
long base2 = 0;
base10 = Convert::ToInt32(txtBase10->Text);
base2 = base10 / 128 * 10000000;
base10 %= 128;
base2 = base10 / 64 * 1000000;
base10 %= 64;
base2 = base10 / 32 * 100000;
base10 %= 32;
base2 = base10 / 16 * 10000;
base10 %= 16;
base2 = base10 / 8 * 1000;
base10 %= 8;
base2 = base10 / 4 * 100;
base10 %= 4;
base2 = base10 / 2 * 10;
base10 %= 2;
base2 = base10 / 1 * 1;
base10 %= 1;
}
你不明白什么是二进制数字。如果需要将任何整数转换为其字符串表示,可以执行以下操作:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int base10;
long base2 = 0;
base10 = Convert::ToInt32(txtBase10->Text);
base2 = base10 / 128 * 10000000;
base10 %= 128;
base2 = base10 / 64 * 1000000;
base10 %= 64;
base2 = base10 / 32 * 100000;
base10 %= 32;
base2 = base10 / 16 * 10000;
base10 %= 16;
base2 = base10 / 8 * 1000;
base10 %= 8;
base2 = base10 / 4 * 100;
base10 %= 4;
base2 = base10 / 2 * 10;
base10 %= 2;
base2 = base10 / 1 * 1;
base10 %= 1;
}
如果希望它是一个长的而不是一个字符串,可以将其用作函数体,它将执行得更好:
String base2 = Convert.ToInt32(str,2).ToString();
String base8 = Convert.ToInt32(str,8).ToString();
String base10 = Convert.ToInt32(str,10).ToString();
String base16 = Convert.ToInt32(str,16).ToString();
如果您希望它是一个长的而不是一个字符串,您可以将其用作函数体,它将执行得更好:
String base2 = Convert.ToInt32(str,2).ToString();
String base8 = Convert.ToInt32(str,8).ToString();
String base10 = Convert.ToInt32(str,10).ToString();
String base16 = Convert.ToInt32(str,16).ToString();
你到底在干什么?发布整个函数。编辑-我的不好,它在那里,但格式不好;没别的了。所有计算机都以二进制形式存储所有信息。没有其他方法了。@DmitrySazonov:假设这是为了视觉表现。但是,此函数不存储任何内容。它现在写的是一个盒子,里面有一个投币口。你把一枚硬币放进去,盒子就会热起来。让我们假设函数实际上需要做任何事情,并使它做得很好。注意,这是C++ + CLI,而不是C++。地球上在做什么?发布整个函数。编辑-我的不好,它在那里,但格式不好;没别的了。所有计算机都以二进制形式存储所有信息。没有其他方法了。@DmitrySazonov:假设这是为了视觉表现。但是,此函数不存储任何内容。它现在写的是一个盒子,里面有一个投币口。你把一枚硬币放进去,盒子就会热起来。让我们假设函数实际上需要做任何事情,并使它做得很好。注意,这是C++ + CLI,而不是C++。对于纯粹的表示需要,这将非常好。对于纯粹的代表性的需求,这将非常好。但用这种方法,你会在大量的数字上出错。没有“如果”内部循环:。但是用这种方法,你会在大量的数字上犯错误。