1. Floating point conversion

Hi guys,

I've been looking everywhere to find something about the problem below but can't find anything. As always, you are my last help

Here's - in two lines - what I'm trying to do:

1. The user enters a decimal value (e.g. 2.1)
2. The conversion function should return the hexadecimal floating point value for this (in this example 40066666).

The following website:
http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html
does this for me, but I need it in C so I can integrate it in one of my programs.

I know there's a lot of websites that explain the theory of this conversion and I think I should be able to make it myself (not knowing how long it would take me). I'm pretty sure though, that the source code for this conversion should be available somewhere (or maybe it's even a standard function in some header file?) and that could save me a lot of time.
Therefore my question: does anyone know where I can find a C program (source code) that does the above conversion for me? Please note, this is not lazyness... people seem to have graduated only on doing this conversion.

Any help would be appreciated. Thanks very much in advance,

Ren&#233;

2. PS I had found something interesting but in that example <decimal.h> is used. Again, I've been searching everywhere for it, does anyone know where I could find that header file?

3. > PS I had found something interesting but in that example <decimal.h> is used
http://faq.cprogramming.com/cgi-bin/...&id=1043284385

Is this cheating?
Code:
```union {
unsigned long i;
float f;
} v;
v.f = 2.1;
printf("%lx\n", v.i );```

4. Originally Posted by Salem
> PS I had found something interesting but in that example <decimal.h> is used
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Thanks for that - although it's not very helpful :P, I didn't see it before indeed.

Originally Posted by Salem
Is this cheating?
Maybe it is, but... do you really think I care?

I LOVE YOU

Thanks!!

5. >Maybe it is, but... do you really think I care?
I couldn't help but laugh at this.

6. Way to go Salem. Helping people cheat.

Now the poor OP will go turn that in and fail the class for using something he doesn't even know works or why it works.

7. Sometimes, it's just fun to post a mousetrap to see what happens

8. This particular mousetrap is waiting to snap shut on the first one to try to compile this in 64-bit Linux.

Evil, Salem, evil.

9. Originally Posted by CornedBee
This particular mousetrap is waiting to snap shut on the first one to try to compile this in 64-bit Linux.
Lol, if that's the problem then there isn't a problem. I'm 99% sure I will never compile in 64-bit Linux.
Anyway, yes I agree I have no idea why / how this works, because I've never worked with union and my theoretical knowledge is nigh to zero. I don't like using something when I don't know how it works, but in this case, I had been looking everywhere to find a solution. When a solution this simple was offered I couldn't resist. As soon as I have time, I will try to find out why/how this works.
And btw, this is not some college assignment, it's something that has practical use for my company

10. This is remarkable way to solve this as Salem did. I admit I couldn't think something like this.
The short and sweet introduction to union is:
http://gd.tuwien.ac.at/languages/c/p...rown/c_099.htm

Cheers