如何从文件中读取带符号的字节 [英] How to read signed bytes from a file
本文介绍了如何从文件中读取带符号的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含十六进制字的文件。
I got a file with lines of hex words.
基本上,我想将文件读入一个数组 sbyte []
。
Basically, I want to read the file into an array sbyte[]
.
我知道我可以使用
byte [] >I know probably I can read it into a byte[]
using
byte[] bt = File.ReadAllBytes("fileName");
但如何将其读入带符号的字节数组?
有人可以给我一些想法吗?
But how to read it into a signed byte array? Could somebody give me some ideas?
推荐答案
文件有多大?如果它足够小, File.ReadAllBytes
没问题,你可以这样做:
How big is the file? If it is small enough that File.ReadAllBytes
is fine, you can probably just do:
byte[] bt = File.ReadAllBytes("fileName");
sbyte[] sbt = new sbyte[bt.Length];
Buffer.BlockCopy(bt, 0, sbt, 0, bt.Length);
虽然坦率地说:我会把它保存为 byte []
并担心其他地方签名/未签名。
Although frankly: I'd keep it as a byte[]
and worry about signed/unsigned elsewhere.
这篇关于如何从文件中读取带符号的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文