hexdecode.c.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. hexdecode.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='gpioinfo.c.html' title=' gpioinfo.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='hexdump.c.html' title=' hexdump.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * size_t hexdecode (void const * memory, size_t extent, char buffer [], size_t length);
  24. *
  25. * memory.h
  26. *
  27. * decode a memory region as a string of hex octets separated with
  28. * character HEX_EXTENDER;
  29. *
  30. * allow three string characters for each memory byte; this means
  31. * that the buffer must hold at least three characters or nothing
  32. * will be decoded; the maximum number of bytes is the lesser of
  33. * chars/3 and bytes;
  34. *
  35. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  36. * Copyright (c) 2001-2006 by Charles Maier Associates;
  37. * Licensed under the Internet Software Consortium License;
  38. *
  39. *--------------------------------------------------------------------*/
  40. #ifndef HEXDECODE_SOURCE
  41. #define HEXDECODE_SOURCE
  42. #include &quot;../tools/memory.h&quot;
  43. #include &quot;../tools/number.h&quot;
  44. size_t hexdecode (void const * memory, register size_t extent, char buffer [], register size_t length)
  45. {
  46. register char * string = (char *)(buffer);
  47. register byte * offset = (byte *)(memory);
  48. if (length)
  49. {
  50. length /= HEX_DIGITS + 1;
  51. while ((length--) &amp;&amp; (extent--))
  52. {
  53. *string++ = DIGITS_HEX [(*offset &gt;&gt; 4) &amp; 0x0F];
  54. *string++ = DIGITS_HEX [(*offset &gt;&gt; 0) &amp; 0x0F];
  55. if ((length) &amp;&amp; (extent))
  56. {
  57. *string++ = HEX_EXTENDER;
  58. }
  59. offset++;
  60. }
  61. *string = (char) (0);
  62. }
  63. return (string - buffer);
  64. }
  65. #endif
  66. </pre>
  67. <div class='footerlink'>
  68. [<a href='gpioinfo.c.html' title=' gpioinfo.c '>PREV</a>]
  69. [<a href='toolkit.html' title=' Index '>HOME</a>]
  70. [<a href='hexdump.c.html' title=' hexdump.c '>NEXT</a>]
  71. </div>
  72. </body>
  73. </html>