hexout.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*====================================================================*
  2. *
  3. * void hexout (void const * memory, size_t extent, char c, char e, FILE * fp);
  4. *
  5. * memory.h
  6. *
  7. * print memory as a series of hexadecimal octets seperated by
  8. * character c; normally, character c will be HEX_EXTENDER as
  9. * defined in number.h;
  10. *
  11. * for example, hexout (memory, 6, ':', ';', stdout) would print:
  12. *
  13. * 00:B0:52:00:00:01;
  14. *
  15. * Motley Tools by Charles Maier;
  16. * Copyright (c) 2001-2006 by Charles Maier Associates;
  17. * Licensed under the Internet Software Consortium License;
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef HEXOUT_SOURCE
  21. #define HEXOUT_SOURCE
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include "../tools/memory.h"
  25. #include "../tools/number.h"
  26. void hexout (void const * memory, size_t extent, char c, char e, FILE * fp)
  27. {
  28. byte * offset = (byte *)(memory);
  29. while (extent--)
  30. {
  31. putc (DIGITS_HEX [(* offset >> 4) & 0x0F], fp);
  32. putc (DIGITS_HEX [(* offset >> 0) & 0x0F], fp);
  33. if ((extent) && (c))
  34. {
  35. putc (c, fp);
  36. }
  37. offset++;
  38. }
  39. if (e)
  40. {
  41. putc (e, fp);
  42. }
  43. return;
  44. }
  45. #endif