Skip to content

Bit manipulation not working with 64 bit values #12099

@JDat

Description

@JDat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions