0

I have a file which I have to read from my JAVA code. I can open file in HEX editor, then content is '00 01 00 00' in the opened file from HEX editor.

I want to do following operation from my JAVA code:- 1. read the content. 2. print it. (It should print as 00 01 00 00). So that I can perform some operation on data.

But the problem is,

When I am doing above operation on the file using "FileinputStream" then instead of printing as '00 01 00 00' it is printing as '0 1 0 0' that is every byte is converted into the decimal value.

So is there any way I can perform my desired operation?

Pratik
  • 109
  • 1
  • 5
  • 14
  • There's no such thing as a "hex byte" - there are just bytes. Unless this is *actually* a text representation? It's not at all clear to me what your "convert into the decimal (00000100)16 = ()10" means either... – Jon Skeet Apr 29 '15 at 13:05
  • It's not clear if your file is binary or text. Does your file contains strings of 0's and 1's (visible in a text editor) or is it a binary file? – daphshez Apr 29 '15 at 13:05
  • 2
    You've confused Jon Skeet. Now the apocalypse can begin. – christopher Apr 29 '15 at 13:06
  • Do you have only 0s and 1s? or do you also have 0 1 2 3 4 5 6 7 8 9 A B C D E F? – morgano Apr 29 '15 at 13:08
  • @morgano Yes I have both numbers and alphabets. – Pratik Apr 30 '15 at 10:11
  • edited question in more understandable format. – Pratik Apr 30 '15 at 11:54
  • reading seems to work and printing is answered at http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java – muued Apr 30 '15 at 11:59
  • Show code. Probable missing a 0 in format: `printf("%02x ", 0xFF & b);` – Joop Eggen Apr 30 '15 at 12:12

0 Answers0