Tag Archives: c

Bitfun: Popcount, Sideways sum, Hamming weight

Bitcount, popcount, sideway sum, Hamming weight

I was going through some simple coding puzzles yesterday night and became fascinated by this seemingly interesting function:

int CountBits (unsigned int x ) {
  static unsigned int mask[] = {

  int i ;
  int shift ; /* Number of positions to shift to right*/
  for (i = 0, shift = 1; i < 5; i++, shift *= 2)
    x = (x & mask[i]) + ((x >> shift) & mask[i]);
  return x;

Continue reading

ELM327 to RS232 in Linux

I have been having car problems recently. However, these inspired me to dig a little into the car ECU. ECUs (engine control units) are able to give out a myriad of information, like systems’ fault codes, real-time RPM, air-flow, fuel consumption, voltage, exhaust state, and lots more. Most modern cars tap into this information and display it on the dashboard via on-board computers.

OBD2 ELM327 to RS232 Linux

I finally received the long-awaited OBD II (OBD 2) (on-board diagnostics) interpreter based on the ELM327 chip yesterday and all I can say is that it’s been a long night.

Continue reading