本帖最后由 jerkoh 于 2010-1-28 22:55 编辑
#include <string.h>
unsigned char buf1[6]={0x00,0x00,0x77,0x88,0x99,0xaa};
unsigned char buf2[4]={0x77,0x88,0x99,0xaa};
void main()
{
while(1)
{
/*
if(memcmp(buf1+2,buf2,sizeof(buf2))==0)
{
for(;;); //12Mhz A time 0.00009 //库函数 最慢
}
else
{
for(;;);
}
*/
if((buf1[5]==buf2[3])&&\
(buf1[4]==buf2[2])&&\
(buf1[3]==buf2[1])&&\
(buf1[2]==buf2[0]))
{
for(;;); //B 12Mhz time 0.000012 最笨方法 最快
}
else
{
for(;;);
}
}
#include <string.h>
unsigned char buf1[6]={0x00,0x00,0x77,0x88,0x99,0xaa};
//unsigned char buf2[4]={0x77,0x88,0x99,0xaa};
union
{
unsigned char buf2[4];
unsigned long ul_buf;
}ul2char;
typedef struct
{
unsigned char STH;
unsigned char STL;
unsigned long ul_data;
}ULdata;
void main()
{
ULdata xdata *ptr;
while(1)
{
ul2char.ul_buf=0x778899aal;
ptr=(ULdata xdata *)(buf1);
if(ul2char.ul_buf==ptr->ul_data)
{
for(;;); //C 12mhz 0.000064 //xdata 改idata 0.000053 复杂操作 速度中等
}
}
除了上面方法 有没其他 ?时间用的更少的 来PK下
|