-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
The current macros in Arduino.h for setting and clearing a bit work only for numbers 32 bits and smaller. If one wants to set a bit in a uint64_t the macro fails. The cause is the 1UL in the macros which is essentially 32 bit,
Solution:
The macros below allow setting a bit for 64bit integers too, but use the 64 bit version of 1 only if size of value is 4 bits or less.
#define bitSet64(value, bit) ((value) |= (sizeof(value)<5?1UL:1ULL) <<(bit))
#define bitClear64(value, bit) ((value) &= ~(sizeof(value)<5?1UL:1ULL) <<(bit))
#define bitWrite64(value, bit, bitvalue) (bitvalue ? bitSet64(value, bit) : bitClear64(value, bit))
It is better to test the sizeof(value) that to test bit as bit often can be a variable so its value cannot be checked compile time.
Metadata
Metadata
Assignees
Labels
No labels