读书人

请问:这是什么算法

发布时间: 2012-02-14 19:19:19 作者: rapoo

请教:这是什么算法?
unsigned int n = mask;

static const signed char tab[64] =
{ -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10,
4, 0, 0, 8, 0, 0, 25, 0, 0, 0, 0, 0, 21, 27 , 15, 31, 11,
5, 0, 0, 0, 0, 0, 9, 0, 0, 24, 0, 0 , 20, 26, 30, 0, 0, 0,
0, 23, 0, 19, 29, 0, 22, 18, 28, 17, 16, 0
};

n &= ~(n-1UL);
n = (n < <16)-n;
n = (n < <6)+n;
n = (n < <4)+n;

return tab[n> > 26];
-------------------------------
mask是输入

这是什么算法?原理是什么?

[解决办法]
externC cyg_uint32 hal_lsbit_index ( cyg_uint32 mask )

Determine the index of the ls bit of the supplied mask.

Because the H8S does not support these by hardware we have to implement the macro HAL_LSBIT_INDEX( index, mask ) as call to this function


Parameters:
mask Bit mask to be processed

Returns:
Index of ls bit in mask
Definition at line 143 of file hal_misc.c.


00144 {
00145 cyg_uint32 n = mask;
00146
00147 static const signed char tab[64] =
00148 { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10,
00149 4, 0, 0, 8, 0, 0, 25, 0, 0, 0, 0, 0, 21, 27 , 15, 31, 11,
00150 5, 0, 0, 0, 0, 0, 9, 0, 0, 24, 0, 0 , 20, 26, 30, 0, 0, 0,
00151 0, 23, 0, 19, 29, 0, 22, 18, 28, 17, 16, 0
00152 };
00153
00154 n &= ~(n-1UL);
00155 n = (n < <16)-n;
00156 n = (n < <6)+n;
00157 n = (n < <4)+n;
00158
00159 return tab[n> > 26];
00160 }


读书人网 >C语言

热点推荐