Go Down

Topic: Subtraction convenience (Read 533 times) previous topic - next topic

fuzzball27

I would like to take advantage of the fact that large numbers subtracted from small numbers returns negative numbers, but this doesn't seem to work in arduino. I am curious why this doesn't work? So:
Code: [Select]

int small = 1000;
int large = 1500;
serial.println(small - large); //I get something like 6500 rather than -500. I smell binary issues.
fuzzball27 >>-->

Nick Gammon

I smell an incomplete piece of code.

Code: [Select]

void setup ()
{
  Serial.begin (115200);
  int small = 1000;
  int large = 1500;
  Serial.println(small - large); //I get something like 6500 rather than -500. I smell binary issues.
}
void loop () {}


Output:

Code: [Select]

-500
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

el_supremo

Ninja Gammon beat me to it :-)

Pete

fuzzball27

I was posting relavent code.
fuzzball27 >>-->

fuzzball27

I figured out the issue. It was part of a different process.
fuzzball27 >>-->

AWOL

Quote
I was posting relavent code.

But not all of the relevant code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy