最快的方式从无符号整数(C ++)中读取最左边的位? [英] Fastest way to read Left-Most bit from unsigned int (C++)?

查看:133
本文介绍了最快的方式从无符号整数(C ++)中读取最左边的位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



从无符号整数读取最左位的最快速方式是什么?


What is the fastest way to read the Left-Most bit from unsigned int ?

感谢,

SW

Thanks,
SW

推荐答案

i >> (sizeof(unsigned int) * CHAR_BIT - 1)

code>,乘法和减法将由编译时由任何合理的编译器计算,所以这应该成为一个右移指令,这是大约与你会得到的一样快。

The sizeof, multiplication, and subtraction will be computed at compile-time by any reasonable compiler, so this should become a single right-shift instruction, which is about as fast as you will get.

这篇关于最快的方式从无符号整数(C ++)中读取最左边的位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆