Combine numbers within array

Hello all,

Is there a way to put together 2 parts of a array?
Say I have an array: 82 81 80 1 3 E5 79 EA 14 6A

I want to combine the 3 and E5 and write it into a different variable. So X would look like 3E5.
Can I use strcat for this, or does there need to be 2 arrays?

Thanks for your help.

byte single[] ={ 82, 81, 80, 1, 3, E5, 79, EA, 14, 6A }

int two_single = (single[4] << 8) + single[5];
byte single[] ={ 82, 81, 80, 1, 3, E5, 79, EA, 14, 6A }

Did you try compiling this? If not, why did you post it without warning that is was possibly nonsense?

Say I have an array: 82 81 80 1 3 E5 79 EA 14 6A

An array of what? That little detail is critical.

So X would look like 3E5.

What is X? That little detail is also critical.

Can I use strcat for this?

Depends on what type the array is.

, or does there need to be 2 arrays

For what?

PaulS:

byte single[] ={ 82, 81, 80, 1, 3, E5, 79, EA, 14, 6A }

Did you try compiling this? If not, why did you post it without warning that is was possibly nonsense?

Say I have an array: 82 81 80 1 3 E5 79 EA 14 6A

An array of what? That little detail is critical.

So X would look like 3E5.

What is X? That little detail is also critical.

Can I use strcat for this?

Depends on what type the array is.

, or does there need to be 2 arrays

For what?

The array is Byte data[]
X is an integer.
What would be example code of strcat in my type of situation?
I want X = 3E5 in the end.

The array is Byte data[]

E5 is not a valid byte value. It is meaningless in anything other than a character context.

0xE5, on the other hand IS a valid byte value.

So, back up and explain what you are trying to do, not how you think you want to do it.

Sorry, I should have specified. It is in HEX. So it is 0xE5

The application is that it is reading data off of an engine controller.
It sends the data in crc32 format, so it has 3 header and 4 checksum bytes. I want to combine the 3 and E5 to make 997 in DEC format, which would correlate to 99.7% throttle position.
The raw data stream coming out of the canbus controller just shows the HEX values with out the leading 0x.

So, 0x03 * 256 + 0xE5 = 768 + 229 = 997.

Or (0x03 << 8) + 0xE5 = 0x3E5.

so could I just go
x = (data[4] << 8 ) + data[5]; ? (no space between the 8 and ))

Well, I don't think there is a smiley face operator in C/C++, but, yeah, something like that.

I would prefer:-

x = (data[4] << 8 | data[5];

Thank you all, It works like a charm!

I would prefer:-

Probably work better if the parentheses matched, but, why is that preferred over addition?

Yes it would.
I think an OR is cleaner and reflects more what is happening.