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

number conversion

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



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

number conversion
PostPosted: Fri Jun 27, 2008 4:57 pm     Reply with quote

hi i am reading a 16bit adc and i am reading a value for example 0f 28766 but the last bit is not stable so i want to ignore or strip of the last digit so my reading is 2876 any suggestions please

many thanks Andrew
Guest








Re: number conversion
PostPosted: Fri Jun 27, 2008 5:31 pm     Reply with quote

morebudwiser wrote:
hi i am reading a 16bit adc and i am reading a value for example 0f 28766 but the last bit is not stable so i want to ignore or strip of the last digit so my reading is 2876 any suggestions please...

Even if you strip off the last digit or round off, you still could get an unstable value. 28769..28770 becomes 2876..2877. And if you round off, 28764..28766 becomes 2876..2877. It is inherent in reading analog values that there will always be the chance for some change in a supposedly rock-solid voltage.

Robert Scott
Real-Time Specialties
Guest








PostPosted: Sat Jun 28, 2008 4:42 am     Reply with quote

hi what i want to do is take a 5 digit number say for example 23456 and change it to a four digit number 2345

many thanks andrew
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Jun 28, 2008 4:48 am     Reply with quote

To cut off the last digit of a decimal value:
Code:
value = value / 10;          // 23456 becomes 2345
Or to remove the last digit with rounding you do:
Code:
value = (value + 5) / 10;    // 23456 becomes 2346
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