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

How to convert dec. to hex. in pic16f819 ?

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



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

How to convert dec. to hex. in pic16f819 ?
PostPosted: Sat Dec 11, 2010 5:05 am     Reply with quote

Any ideas on how to convert dec. to hex.?
exe. 43 = 0x2B

thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sat Dec 11, 2010 5:14 am     Reply with quote

Depends what you mean.....

Understand, the PIC, does not 'work' directly in decimal, or hex. It works internally in binary. So when you input a number (typing it in), you have to have code, that accepts the digits, and converts the text sequence, into binary. Once inside the PIC, you can then output this in a huge 'range' of ways. If you 'putc' the value, a single character is sent, who's ASCII value is the number inside the PIC. Or if you use printf, you have then a 'range' of output formats possible. Look at the %x format specifier in printf....

Best Wishes
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

PostPosted: Sat Dec 11, 2010 5:34 am     Reply with quote

I mean how to write source code for convert dec. value to hex. value in my programe,such as built in function.
Johann17943



Joined: 11 Dec 2010
Posts: 11
Location: Germany

View user's profile Send private message

PostPosted: Sat Dec 11, 2010 5:51 am     Reply with quote

Hi sorasit46

The function for dec to hex is:
Code:

int dec_hex(int zahl);
{
int einer,zehner,ergebnis;
ergebnis=0;
zehner=zahl/10;
einer=zahl-(zehner*10);
ergebnis=(zehner<<4)|einer;
return ergebnis;
}

example:

Code:
hex_value=dec_hex(dec_value);
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

PostPosted: Sat Dec 11, 2010 5:56 am     Reply with quote

Hi! Jonann17943

Thanks for the help!

but I correct some code.
Code:
int dec_hex(int zahl);
{
int einer,zehner,ergebnis;
ergebnis=0;
zehner=zahl/[b]16[/b];
einer=zahl-(zehner*[b]16[/b]);
ergebnis=(zehner<<4)|einer;
return ergebnis;
}


My data is int16,not int.
How to modify this source code?
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