Unexpected arithmetic operation output (for concatenation)

I am trying to concatenate a uint8_t array into a uint32_t through a standard concatenation technique using the arithmetic operations. Here's my code:

#include <stdint.h>

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

void bs(){

  uint8_t arr1[] = {23, 56, 78, 50};
  
  uint32_t arr2;
  
  arr2 = (1000000*arr1[0]) + (10000*arr1[1]) + (100*arr1[2]) + (arr1[3]) ;
  
  Serial.print(arr1[3]);
}

void loop() {}

The output is: 22978026

The output should be pretty obvious. But still I ran the same code on another platform and it worked as expected and gave me 23567850. Am I missing something here? Could I give more info to help find the problem here?

abdul_hannan:
Could I give more info to help find the problem here?

Perhaps google for "big-endian" and "little-endian" or "endianness" to find out about different byte order on different systems. Or read Wikipedia about that.

I think you are running afoul of the old 16-bit integer arithmetic "gotcha".
Try:

arr2 = (1000000L*arr1[0]) + (10000L*arr1[1]) + (100L*arr1[2]) + (arr1[3]) ;

Pete

abdul_hannan:
@el_supremo yes, that worked. Thanks a lot! :slight_smile:

By the way, that is NOT concatenation. That is byte shifting.