# divide 2 hex numbers

• 04-15-2007
dust555
divide 2 hex numbers
hi

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?

Thanks
Dust
• 04-15-2007
MacGyver
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.
• 04-15-2007
Dave_Sinkula
Something like this?
Code:

```#include <stdio.h> int main() {   unsigned int a = 0x6644, b = 0xCC88;   double result = (double)a / b;   printf("%X / %X = %g\n", a, b, result);   return 0; } /* my output 6644 / CC88 = 0.5 */```
• 04-15-2007
dust555
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?
• 04-15-2007
Dave_Sinkula
Quote:

Originally Posted by dust555
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?
• 04-15-2007
Salem
> 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.