函数定义
firstbithigh function
Gets the location of the first set bit starting from the highest order bit and working downward, per component.
For a signed integer, the first significant bit is zero for a negative number.
firstbitlow function
Returns the location of the first set bit starting from the lowest order bit and working upward, per component.
函数调用参数及返回值对照表(-31 到 31)
| dec | bin | firstbithigh() | firstbitlow() |
|---|---|---|---|
| -31 | 11100001 | 4 | 0 |
| -30 | 11100010 | 4 | 1 |
| -29 | 11100011 | 4 | 0 |
| -28 | 11100100 | 4 | 2 |
| -27 | 11100101 | 4 | 0 |
| -26 | 11100110 | 4 | 1 |
| -25 | 11100111 | 4 | 0 |
| -24 | 11101000 | 4 | 3 |
| -23 | 11101001 | 4 | 0 |
| -22 | 11101010 | 4 | 1 |
| -21 | 11101011 | 4 | 0 |
| -20 | 11101100 | 4 | 2 |
| -19 | 11101101 | 4 | 0 |
| -18 | 11101110 | 4 | 1 |
| -17 | 11101111 | 4 | 0 |
| -16 | 11110000 | 3 | 4 |
| -15 | 11110001 | 3 | 0 |
| -14 | 11110010 | 3 | 1 |
| -13 | 11110011 | 3 | 0 |
| -12 | 11110100 | 3 | 2 |
| -11 | 11110101 | 3 | 0 |
| -10 | 11110110 | 3 | 1 |
| -9 | 11110111 | 3 | 0 |
| -8 | 11111000 | 2 | 3 |
| -7 | 11111001 | 2 | 0 |
| -6 | 11111010 | 2 | 1 |
| -5 | 11111011 | 2 | 0 |
| -4 | 11111100 | 1 | 2 |
| -3 | 11111101 | 1 | 0 |
| -2 | 11111110 | 0 | 1 |
| -1 | 11111111 | -1 | 0 |
| 0 | 00000000 | -1 | -1 |
| 1 | 00000001 | 0 | 0 |
| 2 | 00000010 | 1 | 1 |
| 3 | 00000011 | 1 | 0 |
| 4 | 00000100 | 2 | 2 |
| 5 | 00000101 | 2 | 0 |
| 6 | 00000110 | 2 | 1 |
| 7 | 00000111 | 2 | 0 |
| 8 | 00001000 | 3 | 3 |
| 9 | 00001001 | 3 | 0 |
| 10 | 00001010 | 3 | 1 |
| 11 | 00001011 | 3 | 0 |
| 12 | 00001100 | 3 | 2 |
| 13 | 00001101 | 3 | 0 |
| 14 | 00001110 | 3 | 1 |
| 15 | 00001111 | 3 | 0 |
| 16 | 00010000 | 4 | 4 |
| 17 | 00010001 | 4 | 0 |
| 18 | 00010010 | 4 | 1 |
| 19 | 00010011 | 4 | 0 |
| 20 | 00010100 | 4 | 2 |
| 21 | 00010101 | 4 | 0 |
| 22 | 00010110 | 4 | 1 |
| 23 | 00010111 | 4 | 0 |
| 24 | 00011000 | 4 | 3 |
| 25 | 00011001 | 4 | 0 |
| 26 | 00011010 | 4 | 1 |
| 27 | 00011011 | 4 | 0 |
| 28 | 00011100 | 4 | 2 |
| 29 | 00011101 | 4 | 0 |
| 30 | 00011110 | 4 | 1 |
| 31 | 00011111 | 4 | 0 |
GLSL 相同功能的函数
findMSB
Returns the bit number of the most significant bit in the binary representation of value.
For positive integers, the result will be the bit number of the most significant bit set to 1. For negative integers, the result will be the bit number of the most significant bit set to 0. For a value of zero or negative one, -1 will be returned.
findLSB
Returns the bit number of the least significant bit set to 1 in the binary representation of value. If value is zero, -1will be returned.

本文详细介绍了firstbithighfunction和firstbitlowfunction两个位操作函数的功能及其使用方法,并通过具体的参数及返回值示例帮助理解。同时,给出了GLSL中对应的findMSB和findLSB函数,便于读者在不同编程环境中应用。


被折叠的 条评论
为什么被折叠?



