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

Hex to decimal to character string conversion

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







Hex to decimal to character string conversion
PostPosted: Sat Nov 10, 2001 5:20 pm     Reply with quote

I need to convert a 32 bit hexidecimal integer to decimal, and then to a string of characters that represent the decimal conversion to output to the LCD routine lcd.c in the PICC examples. Anyone ever accomplish this?

Any hints appreciated.

Thanks,
Pat O'Keefe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1048
Tomi
Guest







Re: Hex to decimal to character string conversion
PostPosted: Sun Nov 11, 2001 9:40 am     Reply with quote

I assume that you are talking about a string contains hex data.
In this case you can use a modified version of the gethex() function in "input.c":

byte gethex1(char digit) {
if(digit<='9')
return(digit-'0');
else
return((toupper(digit)-'A')+10);
}

int32 gethex(char *inputString) {
int32 retval;
#byte retvalL = retval
#byte retvalH = retval+1
#byte retvalHL = retval+2
#byte retvalHH = retval+3

retvalHH = gethex1(inputString[0]);
retvalHH <<=4;
retvalHH += gethex1(inputString[1]);
retvalHL = gethex1(inputString[2]);
retvalHL <<=4;
retvalHL += gethex1(inputString[3]);
retvalH = gethex1(inputString[4]);
retvalH <<=4;
retvalH += gethex1(inputString[5]);
retvalL = gethex1(inputString[6]);
retvalL <<=4;
retvalL += gethex1(inputString[7]);
return(retval);
}

main()
{
int32 lResult;
char toConvert[9];
strcpy(toConvert,"1234ABCD"); // fill out the sample string
lResult = gethex(toConvert); // convert the string
printf(LCD_PUTC,"\%lu",lResult); // write it as decimal
}


:=I need to convert a 32 bit hexidecimal integer to decimal, and then to a string of characters that represent the decimal conversion to output to the LCD routine lcd.c in the PICC examples. Anyone ever accomplish this?
:=
:=Any hints appreciated.
:=
:=Thanks,
:=Pat O'Keefe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1054
Charlie U
Guest







Re: Hex to decimal to character string conversion
PostPosted: Sun Nov 11, 2001 9:17 pm     Reply with quote

:=I need to convert a 32 bit hexidecimal integer to decimal, and then to a string of characters that represent the decimal conversion to output to the LCD routine lcd.c in the PICC examples. Anyone ever accomplish this?
:=
:=Any hints appreciated.
:=
:=Thanks,
:=Pat O'Keefe

Pat,
You can use the printf() function to do this. Check the manual and the help.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1059
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