Skip to content

Bit manipulation not working with 64 bit values #261

@JDat

Description

@JDat

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: earlephilhower/arduino-pico#3260

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions