get the integer representation value of a float type variable in C

前端 未结 6 1951
悲哀的现实
悲哀的现实 2020-12-21 13:19

I have the number 20 (0x14) stored in a 32-bit register. The register is allocated to a C float variable representing the value 2.8e-44. Now I want to get the hexadecimal re

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 13:49

    C is considered a weakley typed langauge, which may allow to assign values that belong to different types than the variable they are being assigned with, therefore you can simply do this:

     int integer = 1;  
     float floater =1.1111;
    
     floater = integer;  
    

    This is known as Implicit type conversion, also known as coercion, is an automatic type conversion by the compiler. Some programming languages allow compilers to provide coercion; others require it.

    but consider the following:

    • what happens when the float is less than zero?

提交回复
热议问题