Pages: [1]   Go Down
Author Topic: Subtraction convenience  (Read 352 times)
0 Members and 1 Guest are viewing this topic.
United States
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int small = 1000;
int large = 1500;
serial.println(small - large); //I get something like 6500 rather than -500. I smell binary issues.
Logged

fuzzball27 >>-->

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I smell an incomplete piece of code.

Code:
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:
-500
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ninja Gammon beat me to it :-)

Pete
Logged

Where are the Nick Gammons of yesteryear?

United States
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was posting relavent code.
Logged

fuzzball27 >>-->

United States
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I figured out the issue. It was part of a different process.
Logged

fuzzball27 >>-->

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I was posting relavent code.
But not all of the relevant code.
Logged

"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.

Pages: [1]   Go Up
Jump to: