# Flaoting to Integer conversion

This is a discussion on Flaoting to Integer conversion within the C Programming forums, part of the General Programming Boards category; Hello All, I have timer interrupt routine wherein I need to do some floating point operation. There is no floating ...

1. ## Flaoting to Integer conversion

Hello All,

I have timer interrupt routine wherein I need to do some floating point operation. There is no floating point processor in system. It is basically an embedded system.

If I do floating point operation in interrupt routine, it is heavy overhead for processor.

Can I do same operation but with similar accuracy using integers?

Juganoo

2. You might try fixed point numbers.

What you do, is you set aside a number of binary digits in an integer for the decimal point accuracy. ie:

32 16 8 4 1 | decimal point | 1/2 1/4 1/8 1/16 1/32

Addition and subtraction of fixed point numbers are just the same as that for regular integers. When you divide a fixed point number by another, multiply it by `1' (whatever that is in your system). When you multiply a fixed point number by another, divide it by `1' (again, what it is in your system.) It's great, because both of those operations are bitshifts.. You might try google or programmersheaven to get more help with this.

3. see my sig for an example of fixed point arithmetic instead of floating point to compute a pwetty mandelbwot fwactal

4. bill cosby?

5. Originally posted by ggs
bill cosby?
??????

6. bleh. I saw that _very_ program posted on another board, I SWEAR. but it made a fractal out of ``bill cosby''. Are you stealing SORES from somewhere..?

7. i can assure you 105% that this program is an original creation by me. just because you saw another program that was a whole bunch of code smashed into four lines doesnt mean much

8. well, a few more similarities than that (ie, output... ;O) but on second look yes, the code is very different shocking, that... 105%, you say? whee

lor~, i apologize for teh outburst

9. Originally posted by ggs
well, a few more similarities than that (ie, output... ;O) but on second look yes, the code is very different shocking, that... 105%, you say? whee
well, the fractal is a "standard", that many people can code in their sleep.

10. MOI , can you explain me, how it works??/

Jgnoo

11. uggggggg............

you start out with a sane looking program, replace all the variables with single letters, optimize your code as much as possible for terseness, remove all whitespace, and voila. its really not all that amazing