2023-11-15 09:50:20 +08:00

50 lines
1.2 KiB
C

#include "alg.h"
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
static const char lsb_bitmap[] ={
0,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
};
int find_lsb(uint32_t ui32)
{
uint16_t usmsw = (uint16_t)(ui32 >> 16);
uint16_t uslsw = (uint16_t)(ui32 & 0xffff);
uint8_t ubyte;
if(uslsw)
{
ubyte = (uint8_t)(uslsw & 0xff);
if(ubyte)
{
return (lsb_bitmap[ubyte]);
}
else
{
return (lsb_bitmap[(uint8_t)(uslsw >> 8)] + 8 );
}
}
else
{
ubyte = (uint8_t)(usmsw & 0xff);
if(ubyte)
{
return (lsb_bitmap[ubyte] + 16 );
}
else
{
return (lsb_bitmap[(uint8_t)(usmsw >> 8)] + 24 );
}
}
}