我这样做是对的不是我,十六进制转换 [英] I am doing this right aren't I, hex conversion
问题描述
大家好,
我尝试使用十六进制值解码一个字符串(即:0000,0000,0000,0000),例如
0x0400 = 1024(十进制)我需要在过去选择位,我通过以下方式完成此操作
Hi All,
I am try to decode a bit string (ie: 0000,0000,0000,0000) using a hex value for example
0x0400 = 1024 (dec) I need to pick out bits in the past I have done this via the following
// bit 0
if ((Hexvalue2 & 0x0001) == 0)
{
//MessageBox.Show("bit 0 set");
}
else
{
//MessageBox.Show("bit 0 not set");
}
使用模式0001,0002,0004,0008然后是0010,0020等等,我在Turbo C ++(Borland)中完成了它并且它有工作可以将此方法应用于C#,因为我可以正确读取一个字节,而另一个我可以看到。如果它是零,则标签获得一个值,如果不是,则标签获得另一个。
格伦
(为什么,为什么,我花了昨晚的一半玩这个!)
using the pattern 0001,0002,0004,0008 and then 0010, 0020 and so on, I have done this in Turbo C++ (Borland) and it has worked can this method be applied to C# as I can read one byte correctly and the other I can seem to. If it is a zero a label gets one value and if not a label gets another.
Glenn
(Why, Why, I spent half of last night playing with this!)
推荐答案
你的表达不正确,应该是
Your expression is not correct, it should be
if (Hexvalue2 & 0x0001)
{
MessageBox.Show("bit 0 is set");
}
等。
etc.
这篇关于我这样做是对的不是我,十六进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!