Hi all,(adsbygoogle = window.adsbygoogle || []).push({});

I am wondering is there a way to count the number of bits to the left or right of a given 1 in a 32-bit integer?

For example, if I give the function the number 32 = 0b100000, there are 5 bits to the right of the 1 and hence, 26 bits to the left of the 1.

The catch is, is there a way to do this by simply using bit operations? i.e. no loops or conditionals? Bit operations include: & ^ | << >> ! and ~

Thanks

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Bit Operation Counting

Loading...

Similar Threads - Operation Counting | Date |
---|---|

Operation with tensor quantities in quantum field theory | Dec 9, 2017 |

Operating system concepts in an app by Linux System calls | Nov 16, 2017 |

C/++/# Easy way of counting # processeses running? | Nov 8, 2017 |

C/++/# Copy and assignment operator | Apr 15, 2017 |

C/++/# Why are Move operations more efficient than Copy operations? | Apr 4, 2017 |

**Physics Forums - The Fusion of Science and Community**