2 HEX characters into a string?

Hello everyone,

I have a school project where a BMS (battery managment system) is sending information via CAN bus.
Now I have a problem.
I have filterd out the ID, Subindex and the index.
Now I want to put the ''useful'' data into a string (or somting else).
The CAN bus data is ''send'' in 2 characters at the time
Its is sending the following characters: 02, 52, 01, 9A, A7.
02520 stands for the index and the subindex.
Now I have narrowed it down to 9A and A7 (The values).
These values are suppost to be: 9AA7.
But it is split as 9A and A7.
I need to ''reasamble'' them so I get 9AA7.
Does anyone has a suggestion on how to do this/what command I can use?
I have tried String but It wont/I cant get it to work...

Thanks a lot for a reply!.

Greetings,
Robert

If in doubt, there's always the manual.

After a lot of experimenting (and searching) I fineally found/thought of a solution after a few hours of work…
There are multiple ways.
Here is my code

unsigned long int PART1;
unsigned long int PART2;
unsigned long int TOTAL;
void setup() {
Serial.begin(115200);
}

void loop() {

PART1= 0x9A; //First part
PART2= 0xA7; //Second part

Totaal = (PART1* 256) + PART2; //make from 9A 9A00 + B2 = 9AA7
Totaal = (PART1 << 8) + PART2; //Shift bits

Serial.println(TOTAL, HEX);

delay(1000);
}

R_Bouw:
After a lot of experimenting (and searching) I fineally found/thought of a solution after a few hours of work…
There are multiple ways.
Here is my code

unsigned long int PART1;
unsigned long int PART2;
unsigned long int TOTAL;
void setup() {
Serial.begin(115200);
}

void loop() {

PART1= 0x9A; //First part
PART2= 0xA7; //Second part

Totaal = (PART1* 256) + PART2; //make from 9A 9A00 + B2 = 9AA7
Totaal = (PART1 << 8) + PART2; //Shift bits

Serial.println(TOTAL, HEX);

delay(1000);
}

So instead of using one line of code, you prefer two with bit manipulation and math?

Im not sure what you mean.
There are two options to do it.
One is whit shiftbits (TOTAL = (PART1 << 8) + PART2; //Shift bits).
And the other is (TOTAL = (PART1* 256) + PART2; //make from 9A 9A00 + B2 = 9AA7).
Do you mean this?

Greetings,

Robert

R_Bouw:
Im not sure what you mean.
There are two options to do it.
One is whit shiftbits (TOTAL = (PART1 << 8) + PART2; //Shift bits).
And the other is (TOTAL = (PART1* 256) + PART2; //make from 9A 9A00 + B2 = 9AA7).
Do you mean this?

Greetings,

Robert

I mean you completely ignored AWOL’s post.

Oo sorry,

Thats a solution as well.
I dint understand first what he meant.
My apoligies.
My solution fits better in my code.
Thanks a lot for helping me!

Greetings,

Robert

R_Bouw:
My solution fits better in my code.

How so? It makes no sense that your solution "fits better".

My first post wasent completly correct.
I have to do some math as well to get the right values.
Now I can calculate it in 1 time instead of making it a word and calculating it then.