// 시스템 ms 단위 시간 가져오기
void fnMakeTime(char* strTime){
char fmt[32];
char buf[32];
struct timeval tv;
struct tm *tm;
gettimeofday(&tv, NULL);
if((tm = localtime(&tv.tv_sec)) == NULL){
printf("localtime returns NULL\n");
sprintf(strTime, "%d", 0);
return;
}
strftime(fmt, sizeof(fmt), "%Y%m%d%H%M%S%%03u", tm);
sprintf(buf, fmt, tv.tv_usec/1000);
memcpy(strTime, buf, 18);
printf("fnMakeTime(%s)\n", strTime);
}
string to hex string in c language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | // 스트링을 16진수로 변경 void fnStr2Hex(char* out, char* in){ int idx; int ascii; int len = strlen(in); for(idx=0; idx<len; idx++){ sprintf(out+(idx*2), "%02x", in[idx]); } } // char hex[2] long getDecimal(char* hex){ long rtnVal; char end[4]; char *pEnd = end; rtnVal = strtol(hex, &pEnd, 16); return rtnVal; } // 스트링을 16진수로 변경 void fnHex2Str(char* out, char* in){ int idx; int outIdx; int ascii; char hex[3]; int len = strlen(in); for(idx=0; idx<len; idx+=2){ strncpy(hex, in+idx, 2); out[outIdx++] = getDecimal(hex); } } |
피드 구독하기:
글 (Atom)