leetcode位运算总结

编程入门 行业动态 更新时间:2024-10-26 21:30:57

<a href=https://www.elefans.com/category/jswz/34/1769930.html style=leetcode位运算总结"/>

leetcode位运算总结

·1. 四种GCC内置位运算函数

.html

 int __builtin_ffs (unsigned int x)
     返回x的最后一位1的是从后向前第几位,比如7368(1110011001000)返回4。

·int __builtin_clz (unsigned int x)
返回前导的0的个数。

·int __builtin_ctz (unsigned int x)
返回后面的0个个数,和__builtin_clz相对。比如7368(1110011001000)返回3。

·int __builtin_popcount (unsigned int x)
返回二进制表示中1的个数。

·int __builtin_parity (unsigned int x)
返回x的奇偶校验位,也就是x的1的个数模2的结果。

此外,这些函数都有相应的usigned long和usigned long long版本,只需要在函数名后面加上l或ll就可以了,比如int __builtin_clzll。

2. 位运算理论

.md

.html

异或运算 /

3.=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.essearch_pc_relevant&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.essearch_pc_relevant

更多推荐

leetcode位运算总结

本文发布于:2024-03-09 04:15:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1723764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:leetcode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!