/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <stdint.h>
static const char digits[]="0123456789ABCDEF";
char *bytetostr(char *buff, uint8_t val)
{
buff[0] = digits[val >> 4];
buff[1] = digits[val & 0x0f];
buff[2] = 0;
return buff;
}
char *bytearrtostring(char *buff, uint8_t *arr, size_t length, int separator)
{
char *result = buff;
do
{
bytetostr(buff, *arr++);
if(--length)
{
buff[2] = separator;
buff += 3;
}
}while(length);
buff = 0;
return result;
}
int main()
{
uint8_t array[] = {0xa1, 0x45, 0xde, 0x67, 0xff, 0x00};
char buff[100];
printf("%s\n", bytearrtostring(buff, array, sizeof(array), '-'));
}