Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #271378

Re: portable way to get highest bit set?

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: portable way to get highest bit set?
Date 2023-10-14 19:05 -0700
Organization A noiseless patient Spider
Message-ID <86cyxgabe6.fsf@linuxsc.com> (permalink)
References (2 earlier) <878r884vi5.fsf@bsb.me.uk> <ug86d3$2c9mp$1@dont-email.me> <87edi0qide.fsf@bsb.me.uk> <ug8r5q$2gqj4$1@dont-email.me> <ug9p1o$2nihu$1@dont-email.me>

Show all headers | View raw


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.

Back to comp.lang.c | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: portable way to get highest bit set? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-14 19:05 -0700
  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
        Re: portable way to get highest bit set? jak <nospam@please.ty> - 2023-10-15 18:05 +0200

csiph-web