Re: hex and ascii
Re: hex and ascii
- Subject: Re: hex and ascii
- From: Ricky Sharp <email@hidden>
- Date: Sat, 5 Jan 2002 14:40:45 -0600
On Saturday, January 5, 2002, at 01:56 PM, Darin Duphorne wrote:
The code snippet below "works," but some of the values are represented
as "ffffff01" for example instead of just "01" (but not all of them).
Any idea why?
You typically get stuff like that when working with signed values. Make
sure you treat each byte as an unsigned char.
Also, the app blocks until all the data is read. For large files, this
is a pain. Any idea how to avoid the character-by-character loop? I
have used bsd command line hex editors that display large files almost
instantaneously.
Hex editors are cool in that you can simply create a view that will
display only a chunk of info. e.g. say your window is currently 20 rows
high and each row will display 32 bytes worth of info. Simply just read
in 640 bytes worth of info (i.e. only read in what you need to currently
display). As the user scrolls, pages, etc. reposition the file pointer
and read the next chunk. You can also do the simple calculation with
the total number of bytes in the file to see what values you need to set
on your vertical scroll bar.
(I can't believe there's not a convertStringToHex: method or the
like.)
It will probably be more efficient to just read a chunk of raw bytes
from your file and just use more plain vanilla C code rather than using
an NSString as the intermediary storage format to store the entire
contents.
Note too that you can also get fancy and cache chunks of data in
anticipation that the user will be doing some scrolling.
___________________________________________________________
Ricky A. Sharp
mailto:email@hidden
Founder & President
Instant Interactive(tm)
http://www.instantinteractive.com