# Bit instructions from C++. Do we have them?

**URL:** <https://discourse.julialang.org/t/bit-instructions-from-c-do-we-have-them/113900>\
**Category:** General Usage\
**Tags:** bit-twiddling\
**Created:** [May 6, 2024, 12:44pm UTC](https://discourse.julialang.org/t/bit-instructions-from-c-do-we-have-them/113900 "2024-05-06T12:44:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [May 6, 2024, 12:44pm UTC](https://discourse.julialang.org/t/bit-instructions-from-c-do-we-have-them/113900/1 "2024-05-06T12:44:01Z")

</div>

From a Twitter post:

 ![bitfuncs](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e92c8b1fbef5b2d544b66f0eb63090478c2339b.jpeg)

Do we have all these? Seems like we do have some of them. Could be good practice to adopt the missing ones.

The source is: [C23 stdbit.h quick reference](https://www.corsix.org/content/stdbit-quick-reference)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 6, 2024, 12:56pm UTC](https://discourse.julialang.org/t/bit-instructions-from-c-do-we-have-them/113900/2 "2024-05-06T12:56:03Z")

</div>

```julia
leading_zeros
# no replacement that I know of
trailing_zeros
# no replacement that I know of
count_ones
# count_ones(x)==1
Base.top_set_bit
prevpow(2,x)
nextpow(2,x)
leading_ones
# no replacement that I know of
trailing_ones
# no replacement that I know of
count_zeros

```
