as input? you just statically defined as a byte array. i don't know how you input the data.
the function i wrote, expects a char *s as an argument. but "d73f7a79" is a const char . C++ is finicky about using const char which are stored in flash as char * which are typically in RAM and can be modified. so I cast the const char * as a char * to satisfy the compiler.
why String? you defined is as byte above
consider the expanded code below which will read a c-string through the serial monitor
byte buf [10];
char t [80];
void
disp (
byte *buf,
int nByte )
{
for (int n = 0; n < nByte; n++) {
sprintf (t, " 0x%02x", buf [n]);
Serial.print (t);
}
Serial.println ();
}
// -----------------------------------------------------------------------------
int
func (
char *s,
byte *buf,
int bufSize )
{
int val;
unsigned i;
for (i = 0; i < strlen(s); i += 2) {
sscanf (&s [i], "%02x", &val);
*buf++ = val;
}
return i/2;
}
// -----------------------------------------------------------------------------
void
setup (void)
{
Serial.begin (9600);
disp (buf, func ((char *)"d73f7a79", buf, sizeof(buf)));
disp (buf, func ((char *)"1234567890123", buf, sizeof(buf)));
}
// -----------------------------------------------------------------------------
void
loop (void)
{
char s [80];
if (Serial.available ()) {
int n = Serial.readBytesUntil ('\n', s, sizeof(s));
s [n] = 0;
disp (buf, func (s, buf, sizeof(buf)));
}
}