'programming/C_C++'에 해당되는 글 279건

  1. 2013.11.07 bin2hex

bin2hex

programming/C_C++ 2013. 11. 7. 14:03
반응형

 

 

 

int bin2hex(char *buf, char *textbuf, int len, int type)
{
    char hexs[]="0123456789ABCDEF";
    int i;
    int j=0;
 
    for(i=0;i<len;i++)
    {
        textbuf[j++] = hexs[ (buf[i]>>4)&0x0f ];
        textbuf[j++] = hexs[ buf[i]&0x0f ];

        if(type==1 && (i+1 != len))
        {
            textbuf[j++] = ' ';
        }
    }
    textbuf[j]=0;
}


<결과>

1)
buf[1234567890ABCDEFㄱㄴㄷㄹㅁ한글입니다][36] type[0]
textbuf[31323334353637383930414243444546A4A1A4A4A4A7A4A9A4B1C7D1B1DBC0D4B4CFB4D9] [72]


2)
buf[1234567890ABCDEFㄱㄴㄷㄹㅁ한글입니다][36] type[1]
textbuf[31 32 33 34 35 36 37 38 39 30 41 42 43 44 45 46 A4 A1 A4 A4 A4 A7 A4 A9 A4 B1 C7 D1 B1 DB C0 D4 B4 CF B4 D9] [107]

 

 

 

 

반응형
Posted by 공간사랑
,