dimanche 31 janvier 2016

Rotate integer for maximum trailing binary zeros

Given 16 bits of data, I need to (using C++11) find the rotation that maximises the number of trailing zeros.

e.g. (using 8 bits for clarity),

10110001 -> 11011000 so rot=1
10000011 -> 11100000 so rot=2
etc.

Obviously it's easy enough to 'brute force' it. But I suspect there is an elegant solution.

Aucun commentaire:

Enregistrer un commentaire