• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading from .HEX file  RSS feed

 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i,am trying to read contents from a .hex file and convert them into characters . For example say the .hex file looks like
FF702445235678
Now i need to read these values and convert them into characters . That is i need to know the value of FF , 70 , 24 an so on .
Any ideas ?
Thanks in advance
 
Jim Ronholm
Greenhorn
Posts: 21
3
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear to me whether the contents of the file is text (chars) that represent hex values, or the file actually contains hex values (possibly viewed with a hex file viewer of some sort).
If it is the second (actually contains the values - not text) then the solution is suprisingly simple. Use the read() method of whichever input stream you are using. This normally returns an int that represents the unicode (ASCII) value of the character from the file. You can cast this with (char) to get the character it represents (unless you just want the number).

If it is the first - actually a text file containing characters that represent hex values, read the values the same way, convert them to char (same way) concatenate them as required, and then use something like Integer.valueOf( yourString , 16)
You could use parseInt(String, int) depending on your needs instead.


Let me know if this isn't clear or if I still don't understand your question.
Jim
[ November 23, 2002: Message edited by: Jim Ronholm ]
[ November 23, 2002: Message edited by: Jim Ronholm ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Let me know if this isn't clear or if I still don't understand your question.

It is actually a .hex file containing hex value . Now if I use the read() method that would read the bytes one by one then the value of 0x736D616C6C6170754069782E6E6574636F6D2E636F6D would give me the values one by one that is value of 0 then the value of x then 7 and so on .Now suppose i strore this value in a String , then how can i convert this hex string into a proper String. The proper String will be containing the value smallapu@in.netcom.com .I hope I,am clear enough.
Thanks in advance.
[ November 24, 2002: Message edited by: raghav mathur ]
[ November 24, 2002: Message edited by: raghav mathur ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ..
got the solution !
thanks anyways
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!