#include"stdio.h"typedef unsignedCharuchar;typedef unsignedCharU8;/*************************************************************** Program full name: Data high and low bit conversion * * * Program function: 1001010101011100 = 0011101010101001**** input: To convert the number of bits to convert data * * * * returns: converted data by default when the data being converted is preceded by an infinite 0******************************************** ***************/intData_to_data (unsignedCharnum,unsignedintdata) { //High and low position. Interchange.UnsignedChari; unsignedintm =0; for(i =0; i<num;i++) {m= (m<<1) + (data&1); Data>>=1; } return(m);}/*************************************************************** Program full name: Data high and low bit conversion * * * Program function: 10010101=10101001**** input : To convert Data * * * return: Converted data ***********************************************************/Uchar reverse_bit (Uchar data) {//High and low position. Interchange.Data= (data<<4)| (data>>4); Data= ((data&0x33) <<2)| ((data&0xCC) >>2); Data= ((data&0x55) <<1)| ((data&0xAA) >>1); returndata;}//get a byte or a word on the specified address#defineMem_b (x) (* ((char *) (x)))#defineMem_w (x) (* ((short *) (x)))//minimum value of maximum value#defineMAX (x, Y) (((x) > (y))? (x): (y))#defineMIN (x, Y) (((x) < (y))? (x): (y))//get the number of bytes occupied by field in a struct#defineFsiz (Type, field) (sizeof (((type *) 0)->field))//gets the offset of a field in the struct (struct)#defineOFFSETOF (Type, field) ((char) & (((type *) 0)->field))//converts two bytes into a word in LSB format#defineFLIPW (Ray) (((short) (Ray) [0]) + (Ray) [1])//converts a word to two bytes in LSB format#defineFLOPW (Ray, Val) \(Ray) [0] = ((val)/ the); (Ray) [1] = (val) &0xFF)//10, get a word of high and low byte#defineWord_lo (XXX) ((byte) ((word) (XXX) & 255))#defineWord_hi (XXX) ((byte) ((word) (XXX) >> 8))//11, returns a multiple of the nearest 8 that is larger than x#defineRND8 (x) (((((x) + 7)/8) * 8)//12, convert one letter to uppercase#defineUPCASE (c) (((c) >= ' A ' && (c) <= ' Z ')? ((c)-0x20): (c))//13, determine if the character is a number that is 10 in value#defineDecchk (c) ((c) >= ' 0 ' && (c) <= ' 9 ')//14, determine if the character is a number that is 16 in value#defineHexchk (c) (\((c)>='0'&& (c) <='9')) ||((c)>='A'&& (c) <='F')) ||((c)>='a'&& (c) <='F')) )//15, one way to prevent overflow#defineInc_sat (val) (val = (val) +1 > (val))? (val) +1: (val))//16, returns the number of array elements#defineArr_size (a) (sizeof ((a))/sizeof ((a[0)))//17, returns the value of an unsigned N-tailed Mod_by_power_of_two (X,n) =x% (2^n)#defineMod_by_power_of_two (val, mod_by) \(DWORD) (Val)& (DWORD) ((mod_by)-1) )/********************************************************************************* Byte2BCD******************* ******************************************************************/Uchar BYTE2BCD (Uchar Data) {Uchar Rslt=0; if(data>= About)return 0x99; while(data>9) {Data-=Ten; Rslt+=0x10; } return(rslt+Data);}/********************************************************************************* BCD2Byte******************* ******************************************************************/Uchar Bcd2byte (Uchar Data) {return(((data>>4) &0x0f)*Ten+ (data&0x0f));}struct_people {unsignedintAge ; Chargender; Doubleincome; Charxx; Charyy;} n;voidTestvoid) {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));}
C Language Tips