展示HN:Bitmask.h,一个用于嵌入式位操作的300字节C99库

1作者: DenisDolya大约 1 个月前原帖
经过多年的嵌入式项目中与冗长的位操作代码斗争,我创建了 bitmask.h 来解决一个简单的问题:大多数位操作库要么过于庞大(类似 STL 风格),要么过于特定于某个平台(编译器内置函数),要么需要重复编写相同的易出错的位操作。这个单头文件的 C99 库将所有基本操作——位设置/清除/检查、范围操作、位计数、迭代——压缩到约 300 字节的机器代码中,并且没有任何内存分配。这正是我在微控制器工作中所需要的,因为每个字节都至关重要,使用的仅是 C99 和手动优化,以保持完全的可移植性。 <p>GitHub: <a href="https://github.com/Ferki-git-creator/Bitmask" rel="nofollow">https://github.com/Ferki-git-creator/Bitmask</a>
查看原文
After years of wrestling with verbose bit-twiddling code in embedded projects, I created bitmask.h to solve a simple problem: most bit manipulation libraries are either too heavy (STL-style), too platform-specific (compiler intrinsics), or require writing the same error-prone bit operations repeatedly. This single-header C99 library packs all essential operations—bit set&#x2F;clear&#x2F;check, range operations, popcount, iteration—into ~300 bytes of machine code with zero allocations. It&#x27;s what I needed for microcontroller work where every byte counts, using only C99 and manual optimizations to remain completely portable.<p>GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;Ferki-git-creator&#x2F;Bitmask" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Ferki-git-creator&#x2F;Bitmask</a>