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 CCS Technical Support

long type negative value occurance

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



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

long type negative value occurance
PostPosted: Thu Dec 06, 2007 1:25 pm     Reply with quote

Hi all,
I am displaying the speed and the duty cycle of the dc motor.
But, in spite of making the speed variable long data type, it sometimes displays negative numbers. So, would you please tell me how I can fix it ?



Code:

Taken back for a while


Last edited by mcad on Thu Dec 06, 2007 3:39 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 06, 2007 1:26 pm     Reply with quote

Use "%lu" to display unsigned 16-bit values. Don't use "%ld".
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Thu Dec 06, 2007 1:38 pm     Reply with quote

thanks sir.
But, I also saw "%04lu" . which is better to use sir ?
Ttelmah
Guest







PostPosted: Thu Dec 06, 2007 3:43 pm     Reply with quote

The '04', just says how many digits to always display, and to use leading zeros. 'u' means to treat the value given as an unsigned value, while 'd' says to treat it as a signed value. The 'key' is to understand that the output specification, is independant of the real 'type' of the internal number. Hence if you have a value of (hex) FFFF, and display this using 'ld', it gets printed as -1, while the same internal value, if printed with 'lu', gets displayed as 65535.
I you have a value of '0', and print it with %lu, you get '0' displayed, but use %04lu, and '0000' gets displayed.

Best Wishes
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Thu Dec 06, 2007 5:25 pm     Reply with quote

Thanks very much sir for your clarification.

Regards
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