Exemplo n.º 1
0
static void
testbitnot(void *data)
{
  struct testdata *test;
  uint8_t *buf;

  test = data;
  buf = (uint8_t *)malloc(test->capa);

  /* different pointers */
  memcpy(buf, test->bytes1, test->capa);
  bitnot(buf, test->expos, test->bytes1, test->pos1, test->size);
  testassert(biteq(buf, 0, test->expected, 0, test->capa * 8),
      "failed to write notd bits to a different pointer");

  /* same pointer */
  memcpy(buf, test->bytes1, test->capa);
  bitnot(buf, test->expos, buf, test->pos1, test->size);
  testassert(biteq(buf, 0, test->expected, 0, test->capa * 8),
      "failed to write notd bits to the pointer");

  free(buf);
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// 將所有旗標反向
bool C_FlagCtrl::Flip()
{
	if(m_pData == nullptr)
		return false;

	unsigned long uiPage = m_ulSize / 8;
	unsigned long uiBits = m_ulSize % 8;
	char *pData = (char *)m_pData;

	for(unsigned long i = 0; i < uiPage; ++i, ++pData)
		*pData = ~(*pData);

	*pData = bitnot(*pData, static_cast<unsigned char>(uiBits));
	return true;
}