How to Convert 8-bit data to 10-bit data?

S

sandeep_mc81

Hi,

I have the following question.

How to convert an 8-bit data to 10-bit data ?

The following C program uses 8-bit data. (Basically FIR filter)

/*********************************************************/
#define MAX 6
typedef unsigned char uint_8


uint_8 fir()
{

uint_8 buffer[MAX], out;

out =( (buffer[0] + buffer[5]) +
((buffer[1] + buffer[4]) * 2) +
((buffer[2] + buffer[3]) * 3 )
) / 16

return out;

}

/*********************************************************/


The whole program needs to be converted to 10-bit data.
Pls let me know how to do it....

Thanks
Sandeep
 
S

sandeep_mc81

Hi,

Pls use signed char in the above program

i.e., typedef signed char t_int8

use t_int8 in place of uint_8....

SORRY FOR THE CONFUSION.

Thanks
Sandeep
 
P

pete

Hi,

Pls use signed char in the above program

i.e., typedef signed char t_int8

use t_int8 in place of uint_8....

SORRY FOR THE CONFUSION.

Your function appears to return a value
calculated from the bytes of an uninitialized array.
What is it really supposed to do?
comp.lang.c doesn't know what an FIR filter is.
 
R

Randy Yates

Hi,

I have the following question.

How to convert an 8-bit data to 10-bit data ?

The following C program uses 8-bit data. (Basically FIR filter)

/*********************************************************/
#define MAX 6
typedef unsigned char uint_8


uint_8 fir()
{

uint_8 buffer[MAX], out;

out =( (buffer[0] + buffer[5]) +
((buffer[1] + buffer[4]) * 2) +
((buffer[2] + buffer[3]) * 3 )
) / 16

return out;

}

/*********************************************************/


The whole program needs to be converted to 10-bit data.
Pls let me know how to do it....

Change int_8 to int_16. Put the 10 bits in the lower 10 bits of
the 16-bit integers, sign-extended. Make the function return int_16.
 
Q

QN

There is a big difference in how one can interpret this requirement.
As Randy pointed out, you can simply change the variable type, this
will keep your samples (where ever they are as Pete pointed out) the
same but allow you room for overflow. Is this what you need the extra
bits for?

Or, do you mean how do you take 8-bit data and convert it to 10-bit
data, using all of the bits. In that case, you'll have to change the
type and shift your data <<2.

QN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top