Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 30-Apr-13 10:07am
Comments
richcb at 30-Apr-13 15:09pm
   
Ok, go ahead and do that.
ThePhantomUpvoter at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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");
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?
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100