[image] JuergenD: Yes, only dictionary lookup. Then that’s easy, you only need to implement the Base.hash and Base.isequal functions, copying the hash(::String) method so that you get the same hash as for String (if desired). For example, to wrap a Vector{UInt8} in this way: struct VectorS… Answer from stevengj on discourse.julialang.org
🌐
Julia Programming Language
discourse.julialang.org › general usage › performance
Conversion of Vector{UInt8} to String without copy - Performance - Julia Programming Language
November 9, 2020 - Hi, use case: large files with a binary structure and embedded “text” elements. Depending on the file size, we either read them fully into mem, or mmap them. Hence in both cases, the data are fully available in memory. Our files potentially have millions of records Because we know the binary format, we know the offset and length of the embedded text element in each record.
Discussions

How to convert UInt8 byte array to string in Swift - Stack Overflow
The first function accepts a UInt8 and converts that to a "\u{}" representation, which is then returned by the function. Second, another function is set up which takes in a UInt8 array as a parameter, then outputs a string. More on stackoverflow.com
🌐 stackoverflow.com
Uint8_t to string
I want to take a variable in uint8_t format and convert it to hex and save it to string variable. I wanted to do it this way. Found some promising infor on ToSting method String received_id = ""; uint8_t received_char = 16; void setup() { // put your setup code here, to run once: ... More on forum.arduino.cc
🌐 forum.arduino.cc
19
0
August 7, 2022
c++ - Convert vector of uint8 to string - Stack Overflow
I have a pointer to a vector of type uint8. How would I take this pointer and convert the data in the vector into a full string representative of its content? More on stackoverflow.com
🌐 stackoverflow.com
c++ - Convert uint8 to string - Stack Overflow
I want to convert a uint8 to a string to compare it with another one. My function gets my Mac Address and now i want to save it in a string. int main(int argc, char *argv[]) { kern_return_t More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
🌐
GitHub
gist.github.com › ebb00e8cfa8cecae7f3cb1bccf2f1ed9
convert uint8 to string in swift · GitHub
To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ... let decripted = [229, 174, 41, 168, 208, 220, 160, 162, 124, 12, 150, 171, 229, 23, 75, 250, 230, 113, 228, 135, 231, 244, 232, 207, 254, 245, 16, 107, 65, 194, 47, 144, 246, 139, 154, 201, 171, 20, 104, 58, 63, 127, 8, 192, 87, 161, 209, 124] let sstr = String(bytes:decripted, encoding: .utf8)
🌐
Bun
bun.com › binary data › convert a uint8array to a string
Convert a Uint8Array to a string - Bun
August 6, 2026 - Bun implements the Web-standard TextDecoder class for converting binary data types like Uint8Array to strings.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Uint8_t to string - Programming - Arduino Forum
August 7, 2022 - I want to take a variable in uint8_t format and convert it to hex and save it to string variable. I wanted to do it this way. Found some promising infor on ToSting method String received_id = ""; uint8_t received_char = 16; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: received_id=received_char.ToString("X"); delay(2000); } But when I compile I get request for member 'ToString' in 'receiv...
Find elsewhere
Top answer
1 of 2
5

1.) it's a little bit faster to eliminate the int array.

2.) adding '0' changes the integer values 0 and 1 to their ascii values '0' and '1'.

3.) it's undefined behaviour to return the address of a local variable. You have to malloc memory in the heap.

4.) yes, just cut it out and do the whole operation all in one

#include <stdio.h>
#include <stdlib.h>

typedef unsigned char uint8_t;

char *convert(uint8_t *a)
{
  char* buffer2;
  int i;

  buffer2 = malloc(9);
  if (!buffer2)
    return NULL;

  buffer2[8] = 0;
  for (i = 0; i <= 7; i++)
    buffer2[7 - i] = (((*a) >> i) & (0x01)) + '0';

  puts(buffer2);

  return buffer2;
}


int main()
{
  uint8_t example = 0x14;
  char *final_string;

  final_string = convert(&example);
  if (final_string)
  {
    puts(final_string);

    free(final_string);
  }
  return 0;
}
2 of 2
1

Here's one way ...

char *uint8tob( uint8_t value ) {
  static uint8_t base = 2;
  static char buffer[8] = {0};

  int i = 8;
  for( ; i ; --i, value /= base ) {
    buffer[i] = "01"[value % base];
  }

  return &buffer[i+1];
}

char *convert_bytes_to_binary_string( uint8_t *bytes, size_t count ) {
  if ( count < 1 ) {
    return NULL;
  }

  size_t buffer_size = 8 * count + 1;
  char *buffer = calloc( 1, buffer_size );
  if ( buffer == NULL ) {
    return NULL;
  }

  char *output = buffer;
  for ( int i = 0 ; i < count ; i++ ) {
    memcpy( output, uint8tob( bytes[i] ), 8 );
    output += 8;
  }

  return buffer;
};

int main(int argc, const char * argv[]) {
  uint8_t bytes[4] = {  0b10000000, 0b11110000, 0b00001111, 0b11110001 };

  char *string = convert_bytes_to_binary_string( bytes, 4 );
  if ( string == NULL ) {
    printf( "Ooops!\n" );
  } else {
    printf( "Result: %s\n", string );
    free( string );
  }

  return 0;
}

... just extend for 16 bytes. There are many ways and it also depends on what do you mean with quick. Embedded systems, ...? You can make translation table to make it even faster, ...

UPDATE

char *convert_bytes_to_binary_string( uint8_t *bytes, size_t count ) {
  if ( count < 1 ) {
    return NULL;
  }

  const char *table[] = {
    "0000", "0001", "0010", "0011",
    "0100", "0101", "0110", "0111",
    "1000", "1001", "1010", "1011",
    "1100", "1101", "1110", "1111"
  };

  size_t buffer_size = 8 * count + 1;
  char *buffer = malloc( buffer_size );
  if ( buffer == NULL ) {
    return NULL;
  }

  char *output = buffer;
  for ( int i = 0 ; i < count ; i++ ) {
    memcpy( output, table[ bytes[i] >> 4 ], 4 );
    output += 4;
    memcpy( output, table[ bytes[i] & 0x0F ], 4 );
    output += 4;
  }

  *output = 0;

  return buffer;
};

int main(int argc, const char * argv[]) {
  uint8_t bytes[4] = {  0b10000000, 0b11110000, 0b00001111, 0b11110001 };

  char *string = convert_bytes_to_binary_string( bytes, 4 );
  if ( string == NULL ) {
    printf( "Ooops!\n" );
  } else {
    printf( "Result: %s\n", string );
    free( string );
  }

  return 0;
}
🌐
OpenGenus
iq.opengenus.org › convert-array-of-uint8t-to-string-in-cpp
Convert array of uint8_t (uint8_t*) to string in C++ [3 methods]
September 30, 2022 - #include <stdlib.h> int main() { uint8_t* input = {12, 1, 65, 90}; std::ostringstream convert; for (int i = 0; i < 4; i++) { convert << (int)input[i]; } std::string key_string = convert.str(); return 0; } With this article at OpenGenus, you must have the complete idea of how to convert array of uint8_t (uint8_t*) to string in C++.
🌐
Our Code World
ourcodeworld.com › articles › read › 164 › how-to-convert-an-uint8array-to-string-in-javascript
How to convert an Uint8Array to string in Javascript | Our Code World
June 7, 2016 - */ function Utf8ArrayToStr(array) { var out, i, len, c; var char2, char3; out = ""; len = array.length; i = 0; while(i < len) { c = array[i++]; switch(c >> 4) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: // 0xxxxxxx out += String.fromCharCode(c); break; case 12: case 13: // 110x xxxx 10xx xxxx char2 = array[i++]; out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); break; case 14: // 1110 xxxx 10xx xxxx 10xx xxxx char2 = array[i++]; char3 = array[i++]; out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); break; } } retu
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Convert uint8 to string - Programming - Arduino Forum
November 19, 2014 - Hi, i'm trying to convert a uint8 to a string but can't figure out how to do it. I want the ID of an RFID card read in to a variable and stored as a string. I can read in the ID of the card as 0x01 0x02 0x03 0x04 0x05 0…
🌐
Bun
bun.com › guides › binary data › uint8array to string
Convert a Uint8Array to a string | Bun Guides
Bun implements the Web-standard TextDecoder class for converting binary data types like Uint8Array to strings.
🌐
Stack Exchange
arduino.stackexchange.com › questions › 29203 › converting-uint8-t-to-string-unexpected-result
esp8266 - Converting uint8_t to String - unexpected result - Arduino Stack Exchange
September 11, 2016 - When I try to return a value of an uint8_t, as a POST response, i got strange result here is the relevant code: uint8_t PaletteBrightness = 255; server.on("/Sync", HTTP_POST, []() { String Sync = "PaletteBrightness:" + PaletteBrightness; Sync += ":end"; Serial.println(Sync); server.send(200, "text/plain", Sync); });
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › how-to-convert-uint8-t-to-string › td-p › 400099
how to convert uint8_t to string - STMicroelectronics Community
November 8, 2018 - This discussion is locked. Please start a new topic to ask your question. ... The library containing SSD1306_Puts() is most probably not. I guess it wants a pointer as first parameter (uint8_t *). ... You cannot. "Strings" are arrays in plain C.
🌐
All About Circuits
forum.allaboutcircuits.com › home › forums › embedded & programming › programming & languages
Converting uint8_t byte data to a string (ESP-NOW) | All About Circuits
October 20, 2020 - I have found this library : https://github.com/yoursunny/WifiEspNow/blob/master/src/WifiEspNow.cpp In order to send data: char msg[60]; int len = snprintf(msg, sizeof(msg), "2")...