The most recent work involves reading The hexadecimal numbers stored in the char array. The code type (ASCII, BCD, float, Hex) of each char data is different. Convert the data type. The implementation is as follows:
String datatrans: char2bcd (unsigned char * C, int Len) {char s [100]; char C1, C2; string STR = ""; for (INT I = 0; I <Len; I ++) {C1 = C [I] & 0x0f; C2 = C [I]> 4; int n = (INT) (C2 & 0x08 + C2 & 0x04 + C2 & 0x02 + C2 & 0x01) <4) + (C1 & 0x08 + C1 & 0x04 + C1 & 0x02 + C1 & 0x01 )); if (n <= 9 & n> = 0) {STR + = "0" ;}str + = ITOA (N, S, 10) ;}return STR ;} void datatrans: char2byte (unsigned char C, unsigned char * s) {for (INT I = 7; I> = 0; I --) {s [I] = C & 0x01; C = C> 1 ;}} float datatrans: char2float (unsigned char * CP) {return * (float *) CP;} string datatrans: char2hex (char A1) {string STR = ""; // int n = (A1 <8) + A2; int n = A1; for (INT I = 2 * sizeof (char)-1; I> = 0; I --) {STR + = "0123456789 abcdef" [(n> I * 4) & 0xf)];} return STR;} int datatrans: hex2oct (unsigned char C1, unsigned char C2) {return (INT) (C1 <8) + (INT) c2 ;}