arduino / arduino/ArduinoCore-API

Bit manipulation not working with 64 bit values

未关闭
#261 0 条评论 0 个 reaction 已指派 0 人 已被 @asumo-1xts 认领 在 GitHub 查看
主要语言
C++
星标
306
派生
150
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先在 Arduino API 中找到标准的 bitRead()、bitWrite()、bitSet()、bitClear()、bitToggle() 和 bit() 宏。将它们的行为与 issue 中的 uint64_t 示例进行比较,并检查链接的 pull request #278。完成标准是支持 64 位值,同时不破坏现有兼容性。

由索引模型根据 Issue 内容生成。

评估

技术栈
cpp
领域
api, embedded-iot
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。