sábado, 23 de junio de 2012

Bit manipulation trick

Given a 32bit integer number d and a bit position x, find an efficient way to shift to the left the bits of d on the positions from x+1 to 32 while leaving the bits on the positions from 0 to x untouched.

For instance, given d = 0b01001110 and x = 3, the return value should be 0b10010110.

Think about it before looking at the response here.

No hay comentarios:

Publicar un comentario