Re: portable way to get highest bit set?
Ben Bacarisse <[email protected]> Wed, 11 Oct 2023 13:56:10 +0100
| Newsgroups | comp.lang.c,alt.comp.lang.c |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
candycanearter07 <[email protected]> writes: > What is the best/most portable way to get the highest bit set? > > ie. 011010001 > to 010000000 While bit twiddling solutions will be needed for some years, it's worth noting that C23 has <stdbit.h> which includes functions (including type-generic ones) like stdc_bit_floor. C++ has had something similar since C++20. -- Ben.