function name :bitclr
description :清除指定位元(0)
Ex: bitclr(0xff,3)
11111111 -> 11110111
bitaddr :0~31
******************************************************/
unsigned int bitclr(unsigned int srcvalue,unsigned char bitaddr)
{
unsigned int mask=1;
return srcvalue&(~(mask<
bitaddr :0~31
******************************************************/
unsigned int bitset(unsigned int srcvalue,unsigned char bitaddr)
{
unsigned int mask=1;
return srcvalue|(mask<
bitaddr :0~31
******************************************************/
unsigned int bitinv(unsigned int srcvalue,unsigned char bitaddr)
{
unsigned int mask=1;
if((srcvalue>>bitaddr)&0x00000001==1)
return srcvalue&(~(mask<
bitaddr :0~31
return : 1:true , 0:false
******************************************************/
unsigned char bitcmp(unsigned int srcvalue,unsigned char bitaddr)
{
if((srcvalue>>bitaddr)&0x00000001==1)
return 1;
else
return 0;
}
/******************************************************
function name :bitget
description :回指定bit 為 0 或 1
Ex: bitget(0x55,3)
01010101 -> 0
bitaddr :0~31
return : get bit value
******************************************************/
unsigned char bitget(unsigned int srcvalue,unsigned char bitaddr)
{
return (srcvalue>>bitaddr)&0x00000001;
}
/******************************************************
function name :bitput
description :設定指定bit 為 0 或 1
Ex: bitget(0x55,3,1)
01010101 -> 01011101
bitaddr :0~31
return : put bit value
******************************************************/
unsigned int bitput(unsigned int srcvalue,unsigned char bitaddr,unsigned char value)
{
if (value==1)
return bitset(srcvalue,bitaddr);
else
return bitclr(srcvalue,bitaddr);
}
/******************************************************
function name :bitSwap
description :將傳入數值low 與 high 位元完全互換
Ex: bitSwap(0x55)
01010101 -> 10101010
return : swap bit value
******************************************************/
unsigned int bitSwap(unsigned int value)
{
unsigned int tmpbit;
unsigned char i;
tmpbit=value;
for (i=0;i<32;i++) { tmpbit=bitput(tmpbit,31-i,bitget(value,i)); } return tmpbit; }