Re: portable way to get highest bit set?

Keith Thompson <[email protected]> Wed, 11 Oct 2023 17:50:09 -0700
Newsgroups comp.lang.c,alt.comp.lang.c
Organization None to speak of
Message-ID <[email protected]>
Bart <[email protected]> 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) [email protected]
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */