divide 2 hex numbers
I have to write a C program that divides 2 hex numbers to get a number with digits behind the comma. like 6644/CC88 = 0,5(decimal)
I heard something about fixed point notation but I can't get it the right way.
Can anyone help me on this?
What is the actual question? You can read in hexadecimal numbers with scanf(). For printing out floating point values, you can set the amount of decimal places by adjusting the %f to reflect what you want. I believe you can do something like %.2f or whatever to get 2 decimal places.
Something like this?
unsigned int a = 0x6644, b = 0xCC88;
double result = (double)a / b;
printf("%X / %X = %g\n", a, b, result);
/* my output
6644 / CC88 = 0.5
The thing is that the program needs to get on a chip with limited space. so double could be a problem. is there a way to do it with char's?
Is it a proven bottleneck, or do you just want to reinvent the wheel?
Originally Posted by dust555
> I heard something about fixed point notation but I can't get it the right way.
I've heard about them as well, and they work just fine.
Maybe you should post your attempt.