View previous topic :: View next topic |
Author |
Message |
Olli Guest
|
Convert hex to decimal number |
Posted: Mon Mar 31, 2003 8:20 pm |
|
|
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: 1934 Location: Norman, OK
|
Re: Convert hex to decimal number |
Posted: Mon Mar 31, 2003 9:02 pm |
|
|
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 |
Posted: Tue Apr 01, 2003 8:11 am |
|
|
:=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 |
Posted: Wed Apr 02, 2003 11:16 am |
|
|
:=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 |
|
|
|