View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
converting hex into char |
Posted: Sun Feb 15, 2004 9:05 pm |
|
|
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
|
Re: converting hex into char |
Posted: Mon Feb 16, 2004 3:30 am |
|
|
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
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
|
|
Posted: Mon Feb 16, 2004 10:04 pm |
|
|
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. |
|
|
|