#include "stdio.h"
typedef unsigned char uchar;
typedef unsigned char u8;
/***********************************************************
****程序全称:数据高低位转换
****程序功能:1001010101011100=0011101010101001
****输 入: 要转换位数 要转换数据
****返 回:转换后的数据
****默认当被转换的数据前面有无穷个0
***********************************************************/
int data_to_data(unsigned char num,unsigned int data)
{ //高低位..互换.
unsigned char i;
unsigned int m = 0;
for(i = 0;i<num;i++){
m= (m<<1)+(data&1);
data >>=1;
}
return(m);
}
/***********************************************************
****程序全称:数据高低位转换
****程序功能:10010101=10101001
****输 入: 要转换数据
****返 回:转换后的数据
***********************************************************/
uchar reverse_bit(uchar data)
{ //高低位..互换.
data=(data<<4)|(data>>4);
data=((data&0x33)<<2)|((data&0xCC)>>2);
data=((data&0x55)<<1)|((data&0xAA)>>1);
return data;
}
//得到指定地址上的一个字节或字
#define MEM_B( x ) ( *( (char *) (x) ) )
#define MEM_W( x ) ( *( (short *) (x) ) )
//最大值最小值
#define MAX( x, y ) ( ((x) > (y)) ? (x) : (y) )
#define MIN( x, y ) ( ((x) < (y)) ? (x) : (y) )
//得到一个结构体中field所占用的字节数
#define FSIZ( type, field ) (sizeof( ((type *) 0)->field ))
//得到一个field在结构体(struct)中的偏移量
#define OFFSETOF(type, field) ((char)&(((type *)0)->field))
//按照LSB格式把两个字节转化为一个Word
#define FLIPW( ray ) ( (((short) (ray)[0]) * 256) + (ray)[1] )
//按照LSB格式把一个Word转化为两个字节
#define FLOPW( ray, val ) \
(ray)[0] = ((val) / 256); \
(ray)[1] = ((val) & 0xFF)
//10,得到一个字的高位和低位字节
#define WORD_LO(xxx) ((byte) ((word)(xxx) & 255))
#define WORD_HI(xxx) ((byte) ((word)(xxx) >> 8))
//11,返回一个比X大的最接近的8的倍数
#define RND8( x ) ((((x) + 7) / 8 ) * 8 )
//12,将一个字母转换为大写
#define UPCASE( c ) ( ((c) >= 'a' && (c) <= 'z') ? ((c) - 0x20) : (c) )
//13,判断字符是不是10进值的数字
#define DECCHK( c ) ((c) >= '0' && (c) <= '9')
//14,判断字符是不是16进值的数字
#define HEXCHK(c) (\
( (c) >= '0' && (c) <= '9')) ||\
((c) >= 'A' && (c) <= 'F')) ||\
((c) >= 'a' && (c) <= 'f'))\
)
//15,防止溢出的一个方法
#define INC_SAT( val ) (val = ((val)+1 > (val)) ? (val)+1 : (val))
//16,返回数组元素的个数
#define ARR_SIZE( a ) ( sizeof( (a) ) / sizeof( (a[0]) ) )
//17,返回一个无符号数n尾的值MOD_BY_POWER_OF_TWO(X,n)=X%(2^n)
#define MOD_BY_POWER_OF_TWO( val, mod_by ) \
( (dword)(val) & (dword)((mod_by)-1) )
/*****************************************************************************
**** Byte2BCD
****
****
*****************************************************************************/
uchar Byte2BCD(uchar Data)
{
uchar Rslt=0;
if (Data>=99) return 0x99;
while(Data>9)
{
Data-=10;
Rslt+=0x10;
}
return(Rslt+Data);
}
/*****************************************************************************
**** BCD2Byte
****
****
*****************************************************************************/
uchar BCD2Byte(uchar Data)
{
return(((Data>>4)&0x0f)*10+(Data&0x0f));
}
struct _People {
unsigned int age;
char gender;
double income;
char xx;
char yy;
}n;
void test(void)
{
u8 x=0x51;
//x=reverse_bit(x);
// printf("%d\n",&x);
//printf("%d\n",MEM_B(&x));
//printf("pos:%d\n",(char *)&n.yy-(char *)&n);
//printf("%d\n",OFFSETOF(struct _People,yy));
printf("%d\n",sizeof(short));
}