c programm code that find the no of zeros in 8 bit deta item.

braindead

Joined May 12, 2010
28
Rich (BB code):
uint8_t bits_that_are_zero(uint8_t num)
{
  return low_bits_that_are_zero(num)
           + low_bits_that_are_zero(num>>4);
}

uint8_t low_bits_that_are_zero(uint8_t num)
{
  uint8_t zeros;
  num &= 0xF;
  
  zeros = (~num)&0x3;

  if(zeros < 2)
    zeros += 1;

  if(num < 4)
    zeros += 1;
  else if(num >=12)
    zeros -= 1;

  return zeros;
}
 
Last edited:
Top