如何在vb.net中的字节数组中读取特定字节?
我使用dim settingsbinary as byte()= my.computer.filesystem.readallbytes(settingsfile)
使用dim settingsbinary aste
,其中settingsfile是我二进制文件的路径。
假设我的二进制文件有三个字节,我想将第一个字节读为布尔值(00 = false,01 = true)。我该如何获得这些字节?我尝试使用这个问题的答案阅读这三个字节,但我无法将其缠绕在上面。
只是为了澄清,我需要单独获取三个字节:获取第一个字节,然后将checkbox1.Checked
设置为第一个字节,依此类推,依此类推。
I have a binary file being loaded into a Byte array using Dim settingsBinary As Byte() = My.Computer.FileSystem.ReadAllBytes(settingsFile)
where settingsFile is the path to my binary file.
Let's say that my binary file has got three bytes and I want to read the first byte as a Boolean (00 = False, 01 = True). How can I get those bytes? I have tried to use this question's answer to read those three bytes, but I can't wrap my head around it.
Just to clarify, I need to get the three bytes separately: Get the first byte, then set CheckBox1.Checked
to the first byte, and so on with the other bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字节数组就像其他任何数组一样工作:您可以使用 indexer 访问特定元素。
然后,您可以将字节转换为布尔值:(
将转换逻辑概括为可用于所有三个字节的方法,将其作为练习给读者。)
A byte array works just like any other array: You can use an indexer to access a specific element.
And then you can convert the byte into a boolean:
(Generalizing the conversion logic into a method that can be used for all three bytes is left as an exercise to the reader.)