반응형

/********************************************************************************
*  1BYTE를 2BYTE의 HEX코드로 표기 즉 앞파벳A는 HEX코드값이  0x41이므로 41로 표기
* 예1)[ABCDEFGHIJ] => [4142434445464748494A]
* 예2)[1234567890] => [31323334353637383930]
* 예3)[가나다라마] => [B0A1B3AAB4D9B6F3B8B6]
*********************************************************************************/
int 1byte_to_2byte_hex(char *sInBuf, int nInBufLen, char *sOutBuf, int *nOutBufLen)
{
        int nIdx = 0;
        char sTempInBuf[1024] = {'\0'};
        char sTempOutBuf[1024] = {'\0'};

        memset(sTempInBuf, 0x00, sizeof(sTempInBuf));
        memcpy(sTempInBuf, sInBuf, nInBufLen);

        for ( nIdx = 0; nIdx < nInBufLen; nIdx++ )
        {
                sTempOutBuf[2*nIdx+1] = (sTempInBuf[nIdx] & 0x0f) < 10 ? (sTempInBuf[nIdx] & 0x0f) + '0': (sTempInBuf[nIdx] & 0x0f) - 10 + 'A';
                sTempInBuf[nIdx] >>= 4;
                sTempOutBuf[2*nIdx] = (sTempInBuf[nIdx] & 0x0f) < 10 ? (sTempInBuf[nIdx] & 0x0f) + '0': (sTempInBuf[nIdx] & 0x0f) - 10 + 'A';
        }

        *nOutBufLen = (nInBufLen * 2);
        strncpy(sOutBuf, sTempOutBuf, (nInBufLen * 2) );

        return 0;
}

 

유사한것을 다른 방식으로 처리

http://uple.net/1071


 

반응형
Posted by 공간사랑
,