nuc*_*eet 1 .net c# bitwise-operators
我有一些int32值.我需要获得更高位的位置,用于表示当前值.
例如:
int value = 155;
Run Code Online (Sandbox Code Playgroud)
在二进制形式中,它将是10011011
如此高位使用位置8.
是否有任何默认或常用方法?
pos 将是基于0的索引
var pos = (int)Math.Log(155, 2);
Run Code Online (Sandbox Code Playgroud)
你当然应该检查一下 yourval>0
有关更棘手的内容,请参阅https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogIEEE64Float
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |