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


Groups > comp.lang.c > #231421

Re: portable way to get highest bit set?

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c, alt.comp.lang.c
Subject Re: portable way to get highest bit set?
Date 2023-10-11 17:50 -0700
Organization None to speak of
Message-ID <87cyxku0ji.fsf@nosuchdomain.example.com> (permalink)
References (1 earlier) <20231011102714.44a870af4dfe68f756974953@g{oogle}mail.com> <ug6huc$1rvp1$1@dont-email.me> <ug6nvv$1va0l$1@dont-email.me> <ug7een$1rvp2$3@dont-email.me> <ug7evl$243f3$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


Bart <bc@freeuk.com> writes:
> On 12/10/2023 01:25, candycanearter07 wrote:
>> On 10/11/23 13:02, Richard Harnden wrote:
>>> Why 0x100000000 and not 0x800000000?

I think there's an extra 0 on both of those constants.

>> Wait, how do you specify a binary constant again?
>
> Use 0b rather than 0x. But without numeric separators, you will need
> to count carefully if you have up to 64 bits.
>
> Easier might be to write 1U<<31 or 1ULL<<63.

C does not currently support binary constants.  C23 adds them, and gcc
and clang both support them as an extension (some other compilers might
also).

In C23, a binary integer constant starts with "0b" or "0B".

C23 will also allow apostrophe as a digit separator (a feature borrowed
from C++), so you can write 0b1100'1001 -- but don't count on any
pre-C23 compilers supporting that as an extension.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: portable way to get highest bit set? candycanearter07 <no@thanks.net> - 2023-10-11 19:25 -0500
  Re: portable way to get highest bit set? Bart <bc@freeuk.com> - 2023-10-12 01:35 +0100
    Re: portable way to get highest bit set? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-10-11 17:50 -0700
    Re: portable way to get highest bit set? candycanearter07 <no@thanks.net> - 2023-10-11 20:03 -0500

csiph-web