# Negativ number

Discussion in 'Programmer's Corner' started by FroceMaster, Mar 24, 2013.

1. ### FroceMaster Thread Starter Well-Known Member

Jan 28, 2012
525
4
Have tried for a while to figure out.
have a simpel number, ex 1, when add 1 it show 2.
when subtract 1 it show 1 Again, and next 0 , but then it show 32767 instead of -1 why ??
number is declared as signed integer.
Code ( (Unknown Language)):
1.
3.   lcd_goto(0x0e);
6.

2. ### spinnaker AAC Fanatic!

Oct 29, 2009
7,426
3,395
what is the data type of offsetgrad?

Jan 28, 2012
525
4

4. ### t06afre AAC Fanatic!

May 11, 2009
5,936
1,226
utoa function is used for converting unsigned numbers to ASCII. For signed numbers try the itoa function Every signed argument passed to the utoa function will come out the other end as a unsigned argument. In the binary system the integer number -1 is 0xFFFF

5. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,969
1,827
The reason is signed integer numbers are represented as a two's compliment number. <= Do stop and read that link.

So when you subtract 1 from zero you get -1, which as a 2's compliment integer is represented by 111 1111 1111 1111.

When you pass that to utoa() the number is taken as an unsigned integer, so it looks like a big positive number.

6. ### FroceMaster Thread Starter Well-Known Member

Jan 28, 2012
525
4

Takker.
that Works.
need to make changes in the temperature Circuit, the voltage drops to much when wire is around 10 m. to the sensor.