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

Convert hex to decimal number

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







Convert hex to decimal number
PostPosted: Mon Mar 31, 2003 8:20 pm     Reply with quote

Hey guys!!
I receive a hex number from the AD converter into the PIC controller and i wonder how to convert it to a decimal. Need program code now...

Olli
___________________________
This message was ported from CCS's old forum
Original Post ID: 13271
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

Re: Convert hex to decimal number
PostPosted: Mon Mar 31, 2003 9:02 pm     Reply with quote

Olli,
We are not here to write your code for you. Here is a link to a site that outlines how you have to approach the problem code wise:

<a href="http://www.festra.com/wwwboard/messages/1848.html" TARGET="_blank">http://www.festra.com/wwwboard/messages/1848.html</a>

Once you have some code and have taken a shot at it we might be able to help you debug it...

Good Luck,


:=Hey guys!!
:=I receive a hex number from the AD converter into the PIC controller and i wonder how to convert it to a decimal. Need program code now...
:=
:=Olli
___________________________
This message was ported from CCS's old forum
Original Post ID: 13274
_________________
Google and Forum Search are some of your best tools!!!!
Sherpa Doug
Guest







Re: Convert hex to decimal number
PostPosted: Tue Apr 01, 2003 8:11 am     Reply with quote

:=Hey guys!!
:=I receive a hex number from the AD converter into the PIC controller and i wonder how to convert it to a decimal. Need program code now...
:=
:=Olli

What kind of A/D converter gives a HEX number? There were some built in the 1950's and 1960's that gave BCD output but I would assume you have a BINARY number you want to convert to decimal.

I don't write code for people, but here is the brute force technique I have used for years. Start by subtracting 100's (or 1000's if the input is 12 bit or more) until the result is negative. Drop a factor of ten and start subtracting again until you get to 1's. If the input is 8 bits or less it is not worth looping the code unless it helps readability.

This is real simple stuff and implimentation is left as an exercise for the student.

___________________________
This message was ported from CCS's old forum
Original Post ID: 13282
John P
Guest







Re: Convert hex to decimal number
PostPosted: Wed Apr 02, 2003 11:16 am     Reply with quote

:=I receive a hex number from the AD converter into the PIC controller and i wonder how to convert it to a decimal. Need program code now...
:=
:=Olli

Here's a link to code that does what you want, and I can't grumble if you just use it verbatim because I use it myself. But if you want to understand how it works, there are notes attached that explain it.

Note that this is general-purpose code to turn a 16-bit quantity into BCD, so it has a ten-thousands output that the 10-bit A/D won't use. You can just ignore it.

<a href="http://www.dattalo.com/technical/software/pic/bcd.txt" TARGET="_blank">http://www.dattalo.com/technical/software/pic/bcd.txt</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13317
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