根据文件填充一组复选框
我试图弄清楚如何使用 BinaryReader
读取文件(不是由我的程序创建的),并相应地选中或取消选中一组复选框。
我设法弄清楚复选框是这样存储的:
Checkbox 1 = 00 01
Checkbox 2 = 00 02
Checkbox 3 = 00 04
Checkbox 4 = 00 08
Checkbox 5 = 00 10
Checkbox 6 = 00 20
Checkbox 7 = 00 40
Checkbox 8 = 00 60
Checkbox 9 = 00 80
Checkbox 10 = 01 00
Checkbox 11 = 02 00
etc
因此,如果在文件中检查了复选框 1、2、6 和 10,则十六进制值将是: 01 23。我如何将其分解,以便程序中的正确复选框将被选中?
I'm trying to figure out how to read a file (not created by my program), using a BinaryReader
, and checking or unchecking a set of checkboxes accordingly.
I've managed to figure out that the checkboxes are stored as such:
Checkbox 1 = 00 01
Checkbox 2 = 00 02
Checkbox 3 = 00 04
Checkbox 4 = 00 08
Checkbox 5 = 00 10
Checkbox 6 = 00 20
Checkbox 7 = 00 40
Checkbox 8 = 00 60
Checkbox 9 = 00 80
Checkbox 10 = 01 00
Checkbox 11 = 02 00
etc
So if, in the file, checkboxes 1, 2, 6, and 10 where checked the hex value would be: 01 23. How would I break this down so that the correct checkboxes in program would be checked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的例子中有一个错字。复选框 8 不应该是 0060,而应该是 0080。因此 123 意味着位:1、2、6、9(而不是 10)。
像这样:
要检查设置了哪些复选框,您可以使用如下代码:
输出:
因此,带有复选框的代码将像这样简单:
I think there is a typo in your example. Checkbox 8 should not be 0060, but rather 0080. So 123 would mean bits: 1, 2, 6, 9 (not 10).
Like this:
To check what check box is set you could use code like this:
The output:
So your code with checkboxes would be as simple as this:
按正确的顺序保留
CheckBox[]
或List
以及CheckBox
引用,以便您可以通过索引引用它们。您将循环遍历各个位值并使用计数器来跟踪与该位关联的索引:Keep a
CheckBox[]
orList<CheckBox>
with theCheckBox
references in the correct order so that you can refer to them by index. You would loop through the individual bit values and use a counter to keep track of the index associated with that bit:这就足够了 - 适当调整上限。
This'd be adequate - adjust the upper limit appropriately.