CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

itoa and negative numbers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pebbert9



Joined: 31 Dec 2010
Posts: 33

View user's profile Send private message

itoa and negative numbers
PostPosted: Tue Sep 14, 2021 8:54 pm     Reply with quote

Hello,

I am having trouble sending negative numbers out to a serial port. Does anyone see the issue with this test code?
I need to use an int48 and it works fine for positive numbers. I am using a PIC33CK32MP502 and compiler 5.105.

Code:

   char strTest[20] = {0};

   signed int48 Test = -100000;

   itoa(Test, 10, strTest);

   fprintf(rs485, "%s\r\n",strTest);


It is sending -4294967295 to the serial port.
Ttelmah



Joined: 11 Mar 2010
Posts: 17485

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 2:07 am     Reply with quote

OK.
Do you _'have'_ to use int48???.
There have been issues with the arithmetic for this type for just about
every compiler release for ages...
I suspect you will find it'll work OK, with int32, or int64.
Report it to CCS, but if you can as a 'get out of the problem' solution,
change to int64. If you need an int48 result, do the conversion using
int64 only. So:
Code:

   itoa((signed int64)Test, 10, strTest);
pebbert9



Joined: 31 Dec 2010
Posts: 33

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 5:39 am     Reply with quote

Thank you!

Converting to int64 worked.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group