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

converting hex into char

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

converting hex into char
PostPosted: Sun Feb 15, 2004 9:05 pm     Reply with quote

Hi,

In my project I am sending data to a serial eeprom using i2c.

I would like to read the eeprom and send the read data to an video OSD interface card (BOB3) in the form of strings.

for example: the video OSD card accepts strings like

ABCD | etc.

Is the data being read from the eeprom be the ascii code, or is it in hex..???

cheers
arun
Al



Joined: 13 Nov 2003
Posts: 28
Location: Belfast

View user's profile Send private message

Re: converting hex into char
PostPosted: Mon Feb 16, 2004 3:30 am     Reply with quote

arunb wrote:

Is the data being read from the eeprom be the ascii code, or is it in hex..???

arun



It shouldn't really matter what form it is stored in the eeprom. Any format whether hex, char or decimal is only a series of bits. So if the letter 'A' was stored in the eeprom as hex it would be 0x41. However if you read this into a char it becomes 'A'. Play about with the following code to see what I mean.

char letter;
letter = 'A';//I had forgot about this line Surprised
printf("Letter: %c, Hex: %x, Decimal %d", letter, letter, letter);

It would not matter if the original declaration was:

int8 letter

The result should be the same.
_________________
Alan Murray


Last edited by Al on Tue Feb 17, 2004 2:54 am; edited 1 time in total
Guest








PostPosted: Mon Feb 16, 2004 10:04 pm     Reply with quote

The code below will convert Hex number to ASCII character

Code:

for (Loop = 0; Loop < 8; Loop++)
{
   Temp = (Array1[Loop] & 0xF0) >> 4;
   if (Temp < 10)
      Array2[Loop * 2] = Temp + 48;
   else
      Array2[Loop * 2] = Temp + 55;

   Temp = (Array1[Loop] & 0x0F)
   if (Temp < 10)
      Array2[(Loop * 2) + 1] = Temp + 48;
   else
      Array2[(Loop * 2) + 1] = Temp + 55;
}



hope this helps.
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