• Post Reply Bookmark Topic Watch Topic
  • New Topic

converting a file into hex but only outputting the first characters  RSS feed

 
tom bannister
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i am struggling to be able to do what it says in the subject line, i have the coding to be able to convert a file into hex digits bu it shows like this:

56789876543567897654356789765435678654
97465981475736458923689236543896547655
23078087f98f7987a987d89798e798f7987d897e etc...

where as i only want the first 8 characters: 56789876

as of yet i have posted this question up in different places on the internet and nobody has been able to solve it, i will post up the code i have that converts a file into hex.

one other way i have thought about going about this is to convert the file into hex, then convert hex into a string and then use "substring(0,8)" to get the first 8 but i dont have a clue how to do this, any answers would be muh appreciated, thanks.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tom bannister wrote:where as i only want the first 8 characters: 56789876

So: first 8 characters, or first 8 hex digits? And if the first, what is a "character"? Because you're reading in bytes.

And either way, why are you translating the entire file if you only need the first 8 characters/digits? printf() is extremely slow.

One tip for you, if it's what you want: an int contains 8 hex digits, and you may find the InputStream.read(bytes) method more useful.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!