Programming binary/16-in-turn floating-point number (similar to reciprocal transfer)

Source: Internet
Author: User

Program to convert:

//Enter a decimal integer to output a float representation of the same memory arrangementInlinefloatI2F (inti) {floatf =0; ASSERT (sizeof(int) ==sizeof(float)); memcpy (&f, &i,4); returnF; } InlineDoubleLl2d (Long Longll) {DoubleD =0; ASSERT (sizeof(Double) ==sizeof(Long Long)); memcpy (&d, &ll,8); returnD; }   /*how to ask Hovertree.com*/

Application:

inti =-1052770304;//The disassembly sees the value is this, actually is a float type, =-12.0floatf =i2f (i); printf ("f=%f\n", F); Long LongLL =0x4004000000000000l;//this is shown in memory. is actually double type 2.5DoubleD =ll2d (LL); printf ("d=%f\n", d);/*how to ask Hovertree.com*/

The principle is to replicate the memory data and then interpret it with different data types.

Recommendation: http://www.cnblogs.com/roucheng/p/cpp11.html

Programming binary/16-in-turn floating-point number (similar to reciprocal transfer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.