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

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

问题描述

结果
什么是读取无符号整型最左边位的最快方法?结果

谢谢,结果
SW


解决方案

  I>> (sizeof的(无符号整数)* CHAR_BIT  -  1)

的sizeof ,乘法和减法将在编译时通过任何合理的编译器计算的,所以这应该成为一个右移位指令,这大约是快,你会得到。


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

Thanks,
SW

解决方案

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

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天全站免登陆