-4

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Unicorn
  • 293
  • 1
  • 4
  • 12
  • 4
    And with an unedited `Blockquote`, no one will invite you to their parties. – Marcelo Cantos Aug 23 '10 at 12:01
  • `char data[] = "0706050403020100";` ? It's a bit hard to decode what you're actually asking. – nos Aug 23 '10 at 12:03
  • no i wan to generate sequential data in that order. – Unicorn Aug 23 '10 at 12:05
  • Can you try it using a character array and see what happens? – President James K. Polk Aug 23 '10 at 12:06
  • 2
    I don't understand your question. I've looked at some of your other questions and it seems a recurring problem for you. You need to put yourself in the readers' shoes. You may even hit the answer yourself doing so. – Bernard Aug 23 '10 at 12:08
  • possible duplicate of [How to input 8 byte hexadecimal number into char array? ](http://stackoverflow.com/questions/3521079/how-to-input-8-byte-hexadecimal-number-into-char-array) – Hans Passant Aug 23 '10 at 13:26

1 Answers1

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. :-)

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154