Posted to tcl by GPS at Sun Sep 16 10:12:58 GMT 2007view raw

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4.  
  5. int main () {
  6. uint64_t targetvalue = 0x00adbeeffeedfaceULL;
  7. uint8_t parts[7] = {0xad, 0xbe, 0xef, 0xfe, 0xed, 0xfa, 0xce};
  8. uint8_t outparts[7];
  9. uint64_t acc = 0;
  10. int i;
  11.  
  12. acc += parts[6];
  13. acc += 0x100 * parts[5];
  14. acc += 0x10000 * parts[4];
  15. acc += 0x1000000ULL * parts[3];
  16. acc += 0x100000000ULL * parts[2];
  17. acc += 0x10000000000ULL * parts[1];
  18. acc += 0x1000000000000ULL * parts[0];
  19. printf ("%llx\n", acc);
  20.  
  21.  
  22. outparts[0] = acc / 0x1000000000000ULL;
  23. outparts[1] = acc / 0x10000000000ULL;
  24. outparts[2] = acc / 0x100000000ULL;
  25. outparts[3] = acc / 0x1000000ULL;
  26. outparts[4] = acc / 0x10000ULL;
  27. outparts[5] = acc / 0x100ULL;
  28. outparts[6] = acc & 0xff;
  29.  
  30. for (i = 0; i < 7; ++i) {
  31. printf ("outparts[%d] = %x\n", i, outparts[i]);
  32. }
  33.  
  34. return EXIT_SUCCESS;
  35. }
  36.