-3

I want to generate this sequential data in C:

data_packet[1] = 0706050403020100 (seed_value)

next

data_packet[2] = 0f0e0d0c0b0a0908

Next will be the next 8 hexadecimal characters and so on for say 100 bytes. How can I do it? Can we do it using character array?

4

1 回答 1

0

You don't want to use a char array since char may or may not be signed (implementation defined). If you are playing with hexadecimal numbers from 0x00 to 0xFF, I strongly recommend using an unsigned char array.

Looks like the values in the array are sequential, from 0 to N. This indicates using a for loop.

The array is a fixed size of 8 bytes. Hmmm, another good candidate for a for loop.

The hard part of your task is the direction of the bytes. For example are filling in the array starting at position 7 or at position 0?

So here is some psuedo code to help you along:

For each value from 0 to N do:
begin
  for array position from 0 to 7 do: // or from 7 to 0
    put 'value' into the array at 'position';
  call function to process the array.
end

For more fun, change the functionality of "put 'value'" to "put random value".

If you want us to actually write your program, let us know. I could use the extra money. :-)

于 2010-08-23T23:19:48.540 回答