其他分享
首页 > 其他分享> > c 工具函数

c 工具函数

作者:互联网

int arrayToStr(unsigned char *buf, unsigned int buflen, char *out,int state)
{
    char strBuf[33] = {0};
    char pbuf[32];
    int i;
    for(i = 0; i < buflen; i++)
    {
        if(state ==1 )
        {
            
        sprintf(pbuf, "%02X", buf[i]);
        }
        else{
            sprintf(pbuf, "%X", buf[i]);
        }
        strncat(strBuf, pbuf, 2);
    }
    strncpy(out, strBuf, buflen * 2);
    printf("out = %s\n", out);
    return buflen * 2;
}
u8 dec_to_hex(int value)
{
    int i;
    char buffer[2];

    u8 hex_temp =0;
    sprintf(buffer, "%x", value);
    hex_temp = (u8)value;

     printf("%x\r\n",hex_temp);

       hex_temp = i;
       return hex_temp;
    // printf("%s\r\n", return_hex);

    // return hex;
}

标签:函数,temp,int,pbuf,hex,char,工具,out
来源: https://blog.csdn.net/c45449210/article/details/119256022