• C

8-bit data type

I want to write a C programme for a 8-bit microprocessor. All the data type used in the program should be 8-bit. I know that char is also 8-bit, but i need to do some arithemic operation, so char may not be suitable. Which data type can i use which is 8-bit and can do some arithemic operation?
ckchan1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ready4DisCommented:
Why would a char not be suitable for arithemic operations?  C can use chars for math, just has a limit from -128 to 127.  This isn't a huge amount of space to work with, but can be used.  What kind of formulas need to be done, then I can try to help you use only 8-bits in the answer.
0
ufolk123Commented:
Hi ckchan1,

I think char data type should be just fine.You can use a set of characters to emulate basic operations for large data lengths  easily.

You could Read

 Anthony Breitzman, "A Class for Representing Large Integers," C/C++ Users Journal, November 1996

for more information on this type of emulation.


ufolk123
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ckchan1Author Commented:
i want to change a 32-bit addition to a 8-bit addition, since can't use 32 bit data type. I need to use 4 8-bit char to do the addition? is it something additional should be done? or just add it?
0
ckchan1Author Commented:
i want to change a 32-bit addition to a 8-bit addition, since can't use 32 bit data type. I need to use 4 8-bit char to do the addition? is it something additional should be done? or just add it?
0
ufolk123Commented:
Hi ckchan1,

I think additions should be straightforward....

Say two numbers are  

x[4]  and  y[4]

then you need a loop like

carry=0;
for(int i=0;i<4;i++)
{
res[i]=(carry+x[i]+y[i])/10;
carry=(carry+x[i]+y[i])%10;
}

You can optimise it futher using bit map operations may be.
I am assuming both the numbers are +ve.

Like that you can device other arithmatic ops


Regards,
ufolk123

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.