problem in printing

my code

void setup()
{
Serial.begin(115200);
uint32_t value = 3600*10;
Serial.println(value);
value = 36000 * 1;
Serial.println(value);

}

void loop()
{

}

output
4294937760
36000

What did you expect when you multiply two sixteen bit signed integers?

Please remember to use code tags when posting code.

void setup()
{
   Serial.begin(115200);
   uint32_t value = 3600UL*10;
   Serial.println(value);
   value = 36000 * 1;
   Serial.println(value);

}

void loop()
{
   
}

output 36000 36000

3600 is an 'int' constant. When you multiply it by another 'int' constant you get an 'int' result EVEN THOUGH AN 'int' CAN'T STORE 36000 (0x8CA0 in hex). The result is truncated to 16 bits and treated as an 'int'. The value is then -29536. When casting the 'int' to 'unsigned long' the size is adjusted first, by sign extension: 0x8CA0 becomes 0xFFFF8CA0 As an unsigned long that evaluates to: 4294937760

36000 is a 'long' constant because the compiler knows it won't fit in an 'int'. The value in hex is 0x00008CA0

When you multiply a 'long' by an 'int' you get a 'long' result: 0x00008CA0 As an unsigned long that evaluates to: 36000

PaulS:

void setup()

{
  Serial.begin(115200);
  uint32_t value = 3600UL*10;
  Serial.println(value);
  value = 36000 * 1;
  Serial.println(value);

}

void loop()
{
 
}



output
36000
36000

Sorry!..New to this forum. I’ll take care next time

Kudos to johnwasser for actually explaining what was happening.

johnwasser: 3600 is an 'int' constant. When you multiply it by another 'int' constant you get an 'int' result EVEN THOUGH AN 'int' CAN'T STORE 36000 (0x8CA0 in hex). The result is truncated to 16 bits and treated as an 'int'. The value is then -29536. When casting the 'int' to 'unsigned long' the size is adjusted first, by sign extension: 0x8CA0 becomes 0xFFFF8CA0 As an unsigned long that evaluates to: 4294937760

36000 is a 'long' constant because the compiler knows it won't fit in an 'int'. The value in hex is 0x00008CA0

When you multiply a 'long' by an 'int' you get a 'long' result: 0x00008CA0 As an unsigned long that evaluates to: 36000

Thank you so much;-)