This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

keil software

how can i convert int value into float in 8051 assebly?i want to find the average of 12 int valuse which may be float so i want the result in float?

Parents
  • how can i convert int value into float in 8051 assebly?
    Basically, you don't. Because the 8051 has no notion whatsoever of what a floating-point number is. You can't convert to something that doesn't exist in the world view of the CPU.

    Nor do you really need to. The average of 12 integers is a fraction. Not all fractions have to be represented as floating-point numbers. Most, indeed, shouldn't. Learn about fixed-point arithmetics.

Reply
  • how can i convert int value into float in 8051 assebly?
    Basically, you don't. Because the 8051 has no notion whatsoever of what a floating-point number is. You can't convert to something that doesn't exist in the world view of the CPU.

    Nor do you really need to. The average of 12 integers is a fraction. Not all fractions have to be represented as floating-point numbers. Most, indeed, shouldn't. Learn about fixed-point arithmetics.

Children
  • my problem is that when i want to get value like 5.8 ,instead of it i got 5 ,is there any method to convert 5 into float?

  • "my problem is that when i want to get value like 5.8"

    Just pre-multiply everything by, say, ten; so that the answer becomes 58 - presto! no floating point required.

    This is the principle of fixed-point maths.

    Prescaling by powers of ten is convenient if you need to display the results in a decimal format; powers of two would be quicker (as they can be implemented with a simple shift).

    "is there any method to convert 5 into float?"

    I've already answered that one!