Re: portable way to get highest bit set?

candycanearter07 <[email protected]> Wed, 11 Oct 2023 11:19:24 -0500
Newsgroups comp.lang.c,alt.comp.lang.c
Organization A noiseless patient Spider
Message-ID <[email protected]>
On 10/11/23 02:27, Anton Shepelev wrote:
> candycanearter07:
> 
>> What is the best/most portable way to get the highest bit
>> set?
>>
>> ie. 011010001
>> to  010000000
> 
> What is your best attempt, even if unsuccessful?
> 

int out;
for(out = 0x100000000; out; out >> 1)
	if(out & input) break;

I'm trying to find something size independent, though.
Or at least able to be swapped out with a #define
-- 
user <candycane> is generated from /dev/urandom