Arduino read string convert to uint8??

i m in a cryptography project and the algorithm is working with a plain text i made in uint8
now i need the user input any text he likes to encrypt
how can i read string from serial and convert it to uint8???
i m kinda new to arduino so if you could explain in detail that'd be great
thanks

how can i read string from serial

and convert it to uint8

Lie your fool head off. A cast is sufficient.

PaulS:
Lie your fool head off. A cast is sufficient.

Not what i asked for!!!

Alan_Carl:
Not what i asked for!!!

But it IS the solution.

A char and a byte and a uint8_t and a int8_t are all the same size. If a function expects one type, and you have another, you can tell the function to use what you have as the type it expects.

If you have a function:

void doSomethingUseless(int8_t *signedBytes);

and an array:

char serialData[80];

you CAN call the function with what you have:

   doSomethingUseless((int8_t *)serialData);

by lying your fool head off (otherwise known as casting).

Alan_Carl:
Not what i asked for!!!

I think you're interested in how to convert an ASCII string of serial input into an 8 bit number?

Casting is not how you'd do that.

Are your strings going to be input in decimal or hex?

Well, whichever way you need it, the easiest way to do it is to include a library and use common functions.

#include <Arduino.h>
#include <stdlib.h>

void setup()
{
  Serial.begin(115200);             //! Initialize the serial port to the PC

  char dec_string[] = "123";
  uint8_t dec_num;
  char hex_string[] = "A5";
  uint8_t hex_num;

  dec_num = atoi(dec_string); // function from stdlib.h to convert ASCII strings into base10 numbers.
  Serial.println(dec_string);
  Serial.println(dec_num);

  hex_num = strtol(hex_string, NULL, 16); // function to convert ASCII strings into base passed as arg.
  Serial.println(hex_string);
  Serial.println(hex_num, HEX);

}

void loop()
{
}

The output will be this:

123
123
A5
A5

Note that the general function used for hex conversion takes ~4x as long as the decimal one. It’s not too hard to write these functions yourself to see why.