Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Bit manipulation not working with 64 bit values

Open JDat opened this issue 3 weeks ago • 0 comments

I am working with Neopixel multistrip project with RPi Pi Pico (not important how and why, just for note).

I need to manipulate bits in uint64_t variable. Standard bitRead(), bitWrite(0, bitSet(), bitClear(), bitToggle() macros not working. They work only up to 32 bits (uint32_t).

I made quick hack in my code to work with 64 bit variables: #define bitRead64(value, bit) (((value) >> (bit)) & 0x01ULL) #define bitSet64(value, bit) ((value) |= (1ULL << (bit))) #define bitClear64(value, bit) ((value) &= ~(1ULL << (bit))) #define bitToggle64(value, bit) ((value) ^= (1ULL << (bit))) #define bitWrite64(value, bit, bitvalue) ((bitvalue) ? bitSet64((value), (bit)) : bitClear64((value), (bit)))

Recommendations: consider to rewrite bitRead(), bitWrite(), bitSet(0, bitClear(), bitToggle() and bit() for 64 bit compatibility if possible and hope it will not break global compatibility.

Original post: https://github.com/earlephilhower/arduino-pico/issues/3260

JDat avatar Dec 08 '25 21:12 JDat