读取并存储阵列中的BYTE数字,以便以后计算BYTE数字 [英] Read and store BYTE Numbers in array for later calculation on BYTE numbers
问题描述
嗨。
我想使用Hex数字。
我想读取一个文件(例如文本文件)并将它们的字符存储在HEX Type中。
然后对这些数据做一些计算。
请帮帮我。
谢谢。
Hi.
I want to work with Hex numbers.
I want to Read a file(ex. text file) and store their character in HEX Type.
and then do some calculations on these data.
please help me.
thank you.
推荐答案
首先,没有HEX类型 - 而且它不太可能存在,因为Hex代表一个数字,而不是一个不同类型的编号。
如果您的意思是想要处理原始格式的文件,那么只需使用字节:
First off, there is no HEX type - and it''s unlikely there ever would be, since Hex is representation of a number, rather than a different type of numbering altogether.
If you mean you want to work on files in their raw form, then just use bytes:
byte[] data = File.ReadAllBytes(@"D:\Temp\myFile.txt");
将文件读入正常的8位字节,不进行任何翻译或文本解释。
Will read your file into normal 8 bits bytes without any translation or text interpretations going on.
for (int i = 0;i < data.Length; i++)
{
data ^= (byte) i;
}
File.WriteAllBytes(@"D:\Temp\MyUselessFile.txt", data);
将单独更改每个字节,并将它们写回新文件,这几乎是无用的。 (阅读并运行相同的代码将会恢复它)。
这是你想到的那种吗?
Will alter each byte individually, and write them back out to a new file, that is pretty much useless. (Reading it in and running through the same code will restore it though).
Is that the kind of thing you were thinking of?
>
这篇关于读取并存储阵列中的BYTE数字,以便以后计算BYTE数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!