arduino / arduino/ArduinoCore-API
Bit manipulation not working with 64 bit values
- Dominant language
- C++
- Stars
- 306
- Forks
- 150
- PR merge metrics
- No merged PRs in 30d
Description
I need to manipulate bits in `uint64_t` variable.
Standard `bitRead()`, `bitWrite()`, `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:
```cpp
#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()`, `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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the standard bitRead(), bitWrite(), bitSet(), bitClear(), bitToggle(), and bit() macros in the Arduino API. Compare their behavior with the uint64_t examples in the issue and inspect linked pull request #278. Done means 64-bit values are supported without breaking existing compatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, embedded-iot
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100