Uint8_t to char array


uint8_t *hash;

I want to convert this to char array. Is there any way to do it i arduino.


char* ca = (char*) hash;

The asterisk '*' indicates that 'hash' is a pointer.

For most purposes you can simply cast the pointer.


uint8_t bytes[] = "Hello World";

Serial.println((char*) bytes);

char* pointer = (char*) bytes;


To access individual bytes, you cast the value the pointer is pointing to.


uint8_t bytes[] = "Hello World";
Serial.println((char) bytes[0]);

char ch = (char) bytes[1];


char* ca = (char*) hash;

gives no error. However ca doesn't contain exact value of hash

#include “sha1.h”
#include <stdlib.h>

void setup(){


void loop() {

uint8_t *hash;

Sha1.print(“This is a message to hash”);
hash = Sha1.result();

for (int j=0;j<20;j++)

_ Serial.print(“0123456789abcdef”[hash*&0xf]);*_

* }*

* Serial.println();*


I am using this sh1 function. Instead of printing the hash value I want to store in a char array or string for further processing.

Well char has a range from -127 - +127, whereas an unsigned char is 0 to 255. If you convert between them using a value outside of the targets range, then it will be the same bit pattern interpreted differently, and in your case anything above 127.