dimanche 3 mai 2020

Finding all numbers which are less than a given no with less no of set bits than the given no but in the same position

How to find all the numbers which are less than a given no and which have less no of set bits than the given no, but whatever no. of set bits each of the generated no has will be in the position same as the given no's set bit positions.Giving one example suppose the given no is 13 (1101 in binary),then all the generated no will be 12(1100 in binary),9 (1001 in binary),8(1000 in binary),5(0101 in binary),4(0100 in binary),1(0001 in binary). As it is visible that in 1100(set bit positions are 2 and 3 as in given no.1101). I want an efficient algorithm for this.

Aucun commentaire:

Enregistrer un commentaire