Convert letters to numbers

Hello,
I have little problem with coverting letters to numbers. I need convert (for example)
char msg = "ABD"; to int num = {1,2,4}; automatically.

Thank you for your answers

Have a look at the ASCII value of your letters.
If you subtract the right number from the character you will get the corresponding number. You can iterate through your string, pick each character from the array and populate the target array appropriately.

@echo_cz, you sent me a PM saying that the answer in Reply #1 did not help. As far as I can see it has all the information you need.

What have you tried taking account of that information?

...R

echo_cz:
I have little problem with coverting letters to numbers. I need convert (for example)
char msg = "ABD"; to int num = {1,2,4}; automatically.

why do you need to convert them?

It is very important part of my project.

echo_cz:
It is very important part of my project.

I'm sure, but why do you need to convert a string to an int array? It is sort of unusual, so perhaps there is an easier/better way to do this.

echo_cz:
It is very important part of my project.

Then how about responding to the Replies from people who have been trying to help you!

...R

Robin2:
Then how about responding to the Replies from people who have been trying to help you!

exactly...

the solution is quite trivial:

const char* myArrays[] = {"ABD", "DEADBEEFFEED", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};

void setup() 
{
  Serial.begin(9600);
  for (auto string : myArrays)
  {
    char* myString = string;
    Serial.println(myString);
    int myArray[strlen(myString)];
    convertStringToIntArray(myArray, myString);
    for(auto i : myArray)
    {
      Serial.println(i);
    }
  }
  // or just...
  char thisString[] = "hello world";
  Serial.println(thisString);
  int myArray[strlen(thisString)];
  convertStringToIntArray(myArray, thisString);
  for(auto i : myArray)
  {
    Serial.println(i);
  }
}

void loop() 
{
  
}

void convertStringToIntArray(int* array, const char* string)
{
  int idx = 0;
  while (string[idx] != '\0')
  {
    if(string[idx] == 32) 
      array[idx] = 0;
    else 
      array[idx] = toupper(string[idx]) - '@';  // or array[idx] = string[idx] - 64;
    idx++;
  }
}

but why?

@echo_cz - now you have sent me a PM asking for more help. It is not our fault that your deadline is today.

Have you looked at the ASCII value for your letters ?

What is the ASCII value of the character H ?
What is the ASCII value of the character e ?
What is the ASCII value of the character l ?
What is the ASCII value of the character o ?

Can you see a pattern here ?

You also haven't responded to the enquiry in reply #5.

Will you please look into the following to see what is going on!

Digit - 0 : ---------------------> 0x03 = 0x30 + 0x00
Digit - 1: ----------------------> 0x31 = 0x30 + 0x01

..........................................................................
..........................................................................

Digit - A: -----------------------> 0x41 = 0x37 + ?
Digit- B : ---------------------> 0x42 = 0x37 + 0x0B
.........................................................................
........................................................................

GolamMostafa:
Will you please look into the following to see what is going on!
...
Digit - 0 : ---------------------> 0x03 = 0x30 + 0x00
...

confusion, I'd say.

GolamMostafa:
Will you please look into the following to see what is going on!

Not much use for someone that probably doesn't know what hex, or a C hex representation is.

post #10 followed post #1!

Not much use for someone that probably doesn’t know what hex, or a C hex representation is.

Let’s post the solution!

post #10 followed post #1!

I never suggested using HEX representation of the numbers, nor would I.

If the OP would just look at and answer the questions asked of him/her then he/she would be a lot further along by now.

Let's post the solution!

Let's not

In fact, post #10 was inspired by post #1 not from the perspective of base; but, from the very essence of exploring solution from hints.

GolamMostafa:
In fact, post #10 was inspired by post #1 not from the perspective of base; but, from the very essence of exploring solution from hints.

Well, that essence has already proved fruitless in this case. :slight_smile:

GolamMostafa:
In fact, post #10 was inspired by post #1 not from the perspective of base; but, from the very essence of exploring solution from hints.

Then in my view it failed to achieve its objective.

A better hint would have been :
If the ASCII value of the character A is 65 (found using Google) then how would you turn it into a 1 ?
If the ASCII value of the character B is 66 (found using Google) then how would you turn it into a 2 ?

Which is where I was trying to lead the OP

UKHeliBob:
Which is where I was trying to lead the OP

But some, it seems, do not want to be led. :slight_smile:

...R

Robin2:
But some, it seems, do not want to be led. :slight_smile:

...R

Does that mean you can LED a horse to water, but you can't make it blink?