/* Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. Author: Keith Packard, MIT X Consortium Invert bit order within each BYTE of an array.  */
BitOrderInvert(unsigned char *buf, size_t nbytes)
/* Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. Author: Keith Packard, MIT X Consortium Invert bit order within each BYTE of an array.  */
BitOrderInvert(unsigned char *buf, size_t nbytes)
{
    for ( ; nbytes > 0; nbytes--, buf++ )
    {
      unsigned int  val = *buf;
      val = ( ( val >> 1 ) & 0x55 ) | ( ( val << 1 ) & 0xAA );
      val = ( ( val >> 2 ) & 0x33 ) | ( ( val << 2 ) & 0xCC );
      val = ( ( val >> 4 ) & 0x0F ) | ( ( val << 4 ) & 0xF0 );
      *buf = (unsigned char)val;
    }
  }