Uint8_t to char array

Hello,

uint8_t *hash;

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

try

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;
Serial.println(pointer);

//...

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];
Serial.println(ch);


//...

char* ca = (char*) hash;

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

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

void setup(){
Serial.begin(9600);

}

void loop() {

uint8_t *hash;

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

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

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

* }*

* Serial.println();*

delay(1000);

}
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.