# Thread: divide 2 hex numbers

1. ## 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

2. 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.

3. 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
*/```

4. 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?

5. 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?

6. > 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.