日期:2014-05-16 浏览次数:20672 次
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define BYTE unsigned char
void charToNumber(BYTE *t, int start, int len) ;
main()
{
char tmp[32]={-63,6,100};
char line[256];
charToNumber(tmp,0,3);
}
/************************************************************/
void charToNumber(BYTE *t, int start, int len)
{
int flag = ((int) 0xff & t[start]); //0xff 255
int index=0;
int i=0;
BYTE num;
double number_tmp = 0;
printf("flag %d\n",flag);
while(1)
{
if(index==len)
break;
printf("index[%d]=======%x\n",index,t[index]);
index++;
}
if (flag > 0x80) //0x80 128
{
index = flag - 0xc1; //0xc1 193
for (i = start + 1; i < start + len; i++) {
num = t[i];
number_tmp += (num - 0x01) * pow(100, index);
printf("t[%d]:%d number_tmp:%f\n",i,t[i],number_tmp);
index--;
}
}
if (flag < 0x80) {
index = flag - 0x3e; //0x3e 62
for (i = start + 1; i < start + len; i++) {
num = t[i];
if (num == 0x66) { //0x66 102
break;
}
&n