Bit manipulation not working with 64 bit values

Open
#261 0 comments 0 reactions 0 assignees View on GitHub

@asumo-1xts is already working on this.

Since Aug 30, 2026.

  • #278 by @asumo-1xts — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
api, embedded-iot

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.

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:

#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

Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arduino/ArduinoCore-API

All issues in arduino/ArduinoCore-API

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.