Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Richard C Bishop 30-Apr-13 15:09pm    
Ok, go ahead and do that.
[no name] 30-Apr-13 15:10pm    
Help you with what? Can you not read a file? Can you not declare a byte array? What have you tried? Where are you stuck? What is it that you think a "HEX" type is?

1 solution

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:
C#
byte[] data = File.ReadAllBytes(@"D:\Temp\myFile.txt");
Will read your file into normal 8 bits bytes without any translation or text interpretations going on.
C#
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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900