Страница 2 из 2

Добавлено: 16 фев 2005, 17:10
Eugie
Absurd, твой вариант надо чуть-чуть доработать :)

Код: Выделить всё

// Permute bytes: 1<->4, 2<->3 (i.e. little-endian<->big-endian for DWORD)
//
inline DWORD invert(DWORD x)
{
  return x<<24|x>>24|(x<<8 & 0xFF0000)|(x>>8 & 0xFF00);
}

// Read bits (cnt <= 16) from an array
//
inline short readbits(unsigned char *p, short from, short cnt) 
{ 
  return invert(*(DWORD*)(p+(from/8))) << from%8 >> (32-cnt);
}
PS. В x86 архитектуре целые храняться в формате little-endian