Is there a convenient way to write simple but long hexadecimal values ​​in c?

I am currently writing code where I need to change an 8 byte variable 1 bit at a time. I was wondering if there is a more convenient way to write a long but simple hex value, for example:

Variable and 0x8000000000000000

I know that I can declare char as 0x80 and then apply it to another type and shift it. I'm just looking for something simpler and more practical.

+3
source share
2 answers

You can use the bitwise left shift operator to make it clearer:

variable & 1ULL << 63
+3
source

well, although this is a shift, but you can use the arduino macro BV(), which is short and convenient:

#define _BV(bit) (1ULL << (bit))

:

var & (0x8 * _BV(60));

:

var & _BV(63);

63- .

+1

All Articles