Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #272711
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: portable way to get highest bit set? |
| Date | 2023-10-15 01:35 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <86r0lw8erq.fsf@linuxsc.com> (permalink) |
| References | (5 earlier) <ug8r5q$2gqj4$1@dont-email.me> <ug9p1o$2nihu$1@dont-email.me> <86cyxgabe6.fsf@linuxsc.com> <ugfo4p$ameh$1@dont-email.me> <ugfrqs$ba5k$1@dont-email.me> |
jak <nospam@please.ty> writes:
> jak ha scritto:
>
>> Tim Rentsch ha scritto:
>>
>>> jak <nospam@please.ty> writes:
>>>
>>>> unsigned long h_bit(unsigned long val)
>>>> {
>>>> int i;
>>>> for(i = 0; val > 1; val /= 2, i++);
>>>> return val << i;
>>>> }
>>>
>>> A nice compact solution. I like the way it
>>> naturally deals with the case when val is zero.
>>
>> This is not true because if Val is 0 also the bit shifted to left
>> is, so also its result is 0. This one of the reason why the exit
>> from the loop is greater than 1.
>
> Sorry about the answer. I have translated your comment badly.
No worries. I see how it works, and it's cool.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar
Re: portable way to get highest bit set? jak <nospam@please.ty> - 2023-10-15 06:00 +0200
Re: portable way to get highest bit set? jak <nospam@please.ty> - 2023-10-15 07:03 +0200
Re: portable way to get highest bit set? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-15 01:35 -0700
csiph-web