Hex format reading from a file

Hi,

I have a problem related to File Reading. I have a file which contains data which is in Hexa format. I have to read that data and push it to a function which takes a parameter of type char. I am able to read the data from the file, which i am getting as characters.

For example: Suppose the Hexa value from the File data is ABCDEFGH. In hexa form 0xAB is one byte. So, while reading this data A is taken as a byte which is not a required format. I am supposed to get AB as a byte, which i am not getting.

Hope you people understand my query.

with regards,

Chandra.

Reply to
Chandra
Loading thread data ...

Hope you understand:

a) this is the wrong newsgroup to post a Computer Science 101 question, and

b) without specifying anything about the file format, delimiters, or even the programming language you're using, you haven't in fact asked a question yet; you've merely stated that you have a problem.

Reply to
larwe

0xGH? Must be the difference between hex and hexa.

Scott

Reply to
Not Really Me

This is a very common, basic embedded coding task. Assuming you do it by hand and not using some library function:

Read in two 8-bit chars. Convert each to a 4-bit hex nibble (digit) (you will need to handle the numbers and the letters seperately, or use a lookup table) Multiple the first by 0x10 and add it to the second

Reply to
cs_posting

On systems where you can afford to waste 64kB like that, your int is probably 32 bits.

Reply to
Arlet

Or, if you can afford a 64K LUT you could do

int *si = (int *)str; char *hex = someOutputBuffer; while (*si) hex++ = bigLut[*si++];

assuming str is properly terminated with two nulls.

Andrew

Reply to
andrew queisser

Nice catch! Ok, version 2.0:

short *si = (short *)str; char *hex = someOutputBuffer; while (*si) hex++ = bigLut[*si++];

Reply to
andrew queisser

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.