试图从字符串中显示二进制文件 [英] Trying to display a Binary from a string
问题描述
大家好,
战斗我需要从字符串4020显示二进制文件,
我使用过该方法
MessageBox.Show(已退回);
Hexvalue2 = Convert.ToUInt32(已退回, 16 );
MessageBox.Show(Hexvalue2.ToString());
将我的字符串转换为可用于
if ((Hexvalue2& 0x0001)== 0 )
{
// MessageBox.Show(hello bit 1 not set);
checkBox1.Checked = 假跨度>;
label9.Text = False;
}
其他
{
// < span class =code-comment> MessageBox.Show(bit 1 set);
checkBox1.Checked = true ;
label9.Text = True;
}
检查位是否已设置并相应地更新字符串这似乎工作正常但位4和32似乎倒了我希望看到二进制数据之前大喊大叫!所以我做了以下
Hexvalue2 = Convert.ToUInt32(IU_status, 2 );
textBox2.Text = Hexvalue2.ToString();
并获得无法找到任何可识别的数字错误。是我正在做什么的正确方法还是我被Convert.To诱惑了?
格伦
您正在从TextBox获取输入并希望将其转换为二进制或十六进制数。
因为您从TextBox中获取输入其数据类型为String,您必须将该String转换为int,long等,具体取决于您的要求。
要将您的数字转换为十六进制数字,请参阅十六进制转换器 [ ^ ]
bcoz将字符串转换为任何数字形式,如int,long, float等等它只是十进制数
要将你的数字转换为二进制,八进制等任何基数,请参阅将十进制转换为任何基数(二进制,八进制或六进制),反之亦然(C#) [ ^ ]
Hi All,
Battling away I need to display a binary from a string "4020",
I have used the method
MessageBox.Show(Returned);
Hexvalue2 = Convert.ToUInt32(Returned, 16);
MessageBox.Show(Hexvalue2.ToString());
to convert my string to a form that can be used that with
if ((Hexvalue2 & 0x0001) == 0)
{
//MessageBox.Show("hello bit 1 not set");
checkBox1.Checked = false;
label9.Text = "False";
}
else
{
// MessageBox.Show("bit 1 set");
checkBox1.Checked = true;
label9.Text = "True";
}
to check if bits are set and update a string accordingly This appears to working fine but bits 4 & 32 seem to inverted I was hoping for a look at the binary data before yelling fowl to higher ups! So I did the following
Hexvalue2 = Convert.ToUInt32(IU_status,2);
textBox2.Text = Hexvalue2.ToString();
and get an Could not find any recognizable digits error. Is the correct way of doing what I''m after or have I been seduced by Convert.To again?
Glenn
You are taking an input from the TextBox and wanted to convert it into binary or hexadecimal number.
Since you take input from the TextBox you have its datatype is String and you have to convert that String into int, long, etc Depending upon your requirement.
To convert your number to Hexadecimal Number refer to Hex Converter[^]
bcoz when you convert string to any numerical form like int, long, float, etc it is in the decimal number only
To convert your Number to any Base like Binary, octal, etc refer to Conversion of Decimal to any Base (Binary, Octal or Hexa) and vice-versa (C#)[^]
这篇关于试图从字符串中显示二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!