void array_to_string(byte array[], unsigned int len, char buffer[]) { for (unsig
ID: 3724592 • Letter: V
Question
void array_to_string(byte array[], unsigned int len, char buffer[]){
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '';
}
char str[32] = "";
array_to_string(data, 16, str);
Serial.println(str);
Serial.println(""); This function been built in arduino and to be used for changing array to string
Questions: Based on this function how we can make array to string function based in this function
void array_to_string(byte array[], unsigned int len, char buffer[])
{
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '';
}
char str[32] = "";
array_to_string(data, 16, str);
Serial.println(str);
Serial.println(""); This function been built in arduino and to be used for changing array to string
Questions: Based on this function how we can make array to string function based in this function
void array_to_string(byte array[], unsigned int len, char buffer[])
{
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '';
}
char str[32] = "";
array_to_string(data, 16, str);
Serial.println(str);
Serial.println(""); This function been built in arduino and to be used for changing array to string
Questions: Based on this function how we can make array to string function based in this function
Explanation / Answer
This function been built in arduino and to be used for changing array to string :-
void array_to_string(byte array[], unsigned int len, char buffer[]){
for (unsigned int i = 0; i < len; i++) {
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '';
}
double data[] = {1000.0, 2.0, 3.4, 7.0, 50.0, 10100.0, 112.0, 33.4, 17.0, 510.0, 11000.0, 22.0, 36.4, 79.0, 570.0, 12.0};
char str[32] = "";
array_to_string(data, 16, str);
Serial.println(str);
Serial.println("");
Now based on above given function,we can make array to string function based in this function by adding doble type array with length 16 ------->
double data[] = {1000.0, 2.0, 3.4, 7.0, 50.0, 10100.0, 112.0, 33.4, 17.0, 510.0, 11000.0, 22.0, 36.4, 79.0, 570.0, 12.0};//this line added in code above
Now when we call function array_to_string(data, 16, str), it will convert double type array data[] to string str and print in ardunio.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.