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


Groups > comp.lang.c > #236222

Re: portable way to get highest bit set?

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c, alt.comp.lang.c
Subject Re: portable way to get highest bit set?
Date 2023-10-12 10:50 +0100
Organization A noiseless patient Spider
Message-ID <87edi0qide.fsf@bsb.me.uk> (permalink)
References <ug5gvh$1jkar$3@dont-email.me> <ug70cu$219ov$1@dont-email.me> <878r884vi5.fsf@bsb.me.uk> <ug86d3$2c9mp$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


jak <nospam@please.ty> writes:

> Ben Bacarisse ha scritto:
>> jak <nospam@please.ty> writes:
>> 
>>> candycanearter07 ha scritto:
>>>> Hi,
>>>> What is the best/most portable way to get the highest bit set?
>>>> ie. 011010001
>>>> to  010000000
>>>
>>> Hi,
>>> I don't think it's the best but the most portable could be the
>>> mathematical approach:
>>>
>>> #include <stdio.h>
>>> #include <math.h>
>>>
>>> int main()
>>> {
>>>      unsigned long val = 3000, ret;
>> Test case: val = 0xFFFFFFFFFFFFFFFF
>
> This is due to the approximation of the floating point:

I know the reason.  I was just pointing out that you need to at least
test the boundary cases!

-- 
Ben.

Back to comp.lang.c | Previous | Next | Find similar


Thread

Re: portable way to get highest bit set? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-12 10:50 +0100

csiph-web