I am a beginner at C programming. I researched how to get a solution to my problem but I didn't find an answer so I asked here. My problem is:
I want to convert a hex array to a string. for example:
it is my input hex: uint8_t hex_in[4]={0x10,0x01,0x00,0x11};
and I want to string output like that: "10010011"
I tried some solutions but it gives me as "101011" as getting rid of zeros.
How can I obtain an 8-digit string?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(){
char dene[2];
uint8_t hex_in[4]={0x10,0x01,0x00,0x11};
//sprintf(dene, "%x%*x%x%x", dev[0],dev[1],2,dev[2],dev[3]);
//sprintf(dene, "%02x",hex_in[1]);
printf("dene %s\n",dene);
}
sprintfthe width and the padding: for examplesprintf(str, "%02X", hex_in[0]);which will generate 2 digits with'0'padding.char dene[2];==>char dene[9];Thensprintf(dene, "%02X%02X%02X", hex_in[0], hex_in[1], hex_in[2], hex_in[3]);