View Single Post
  #24 (permalink)  
Old April 1st, 2004, 09:22 AM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are still dealing with the original input file you told me about,
you should use bytes 8 and 9 for the calculation of INSLength.
Furthermore, these bytes would be the hexadecimal values, so, as
in my previous post:

Code:
INSLength = (16 * atohex(RawPacket[ 8])) + atohex(RawPacket[ 9]);
Where atohex() is a function you write to convert an ascii hex digit
char to his hex value. I told you one way to do this.

Now, as for displaying the body of the file. Again, if you are
still using the original input file, you have following things to
consider:

The first byte you want to print out starts at RawPacket[12].

You will print out a total of INSLength bytes.

Each byte is printed by taking the next two characters from RawPacket
directly to the output file.

You want to print 16 bytes on a line, separated by a single space
character.

Suppose you didn't have any limit on the number of bytes on a
line. Then you would make a loop that does the following:

Starting at RawPacket[12]
  transfer two characters from RawPacket to the output file.
  transfer a space character (' ') to the output file.
  continue until INSLength bytes have been transferred.

How would you do this?

You could have two "counters".
One counter starts with a value of 12, and is used as an
index into RawPacket for the next input character. That
is, it is incremented each time you get a character.

Another counter starts at 0, and is incremented every time the
second input character of each byte is transferred. You
could make a loop with this counter starting at 0 and ending
at (what --- you can figure it out). Now every time you
increment this counter, put a space character to the output
file, so that the output bytes will be separated as required.

Now, the way that I have described is not the only way to approach
the problem; maybe not the most elegant way in some people's
opinion, but it is a way. If you read this and you think
of a better way, go for it. But do something that gets you to
this point.

Please, please, please do this, and get it exactly right before
you continue.




Now, you need to put an endl to the output file after each 16
output bytes to break the lines. A straightforward way is to
make a nested loop that counts from 0 to 15 (increments every
time the outer loop counter is incremented). Whenever the 16th
output byte is printed, then instead of a space, put an endl
to the output file.

Try this, and you are almost home. Still a few details to clean
up.


Dave
Reply With Quote