How to find the position of all ones in a binary number?

for example, given a number 210 (11010010 in binary), where bits 2, 5, 7, and 8 are 1 (starting from the rightmost), then the result is [2 mine5, 7, 8].

are there any efficient solutions?


the level is limited.
I don't know what kind of efficient solution you want, but I tried it myself. In python, what I think should be efficient is actually not efficient. Instead, I think the stupidest method is more efficient.

public static List<Integer> getBitCollections (long bits) {  
    List<Integer> index = new ArrayList<>();  
 int position = 1;  
 while (bits != 0) {  
    if ((bits & 1) != 0) {  
        index.add(position);  
    }  
      positionPP;  
      bits = bits >>> 1;  
  }  
    return index;  
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36b39-4d6d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36b39-4d6d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?