问题描述
除了MSB之外,有人知道类似于De Bruijn的LSB的算法吗?或者是确定MSB的最有效方法?
Does anyone know of an algorithm similar to De Bruijn's LSB, but for MSB? Or alternately the most efficient way of determining the MSB?
我知道Log_2(Val)将执行此操作,但是我不知道这是否是最有效的方法.
I know Log_2(Val) will do this, but I don't know if it's the most efficient method.
我需要它的原因是我需要将little-endian转换为big-endian.我知道这个的标准算法.但是,输入是64位,但通常数字是16或24位,因此不需要99.9%的时间交换整个8个字节.
The reason I need it is I need to convert little-endian to big-endian. I know the standard algorithm for this. However, the input is 64 bit, but typically the numbers will be 16 or 24 bit, so swapping the whole 8 bytes around is unneeded 99.9% of the time.
推荐答案
http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn 吗?
这篇关于等效于De Bruijn LSB,但适用于MSB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!