Binary/hexadecimal to floating point Programming (similar to mutual conversion), hexadecimal points

Source: Internet
Author: User

Binary/hexadecimal to floating point Programming (similar to mutual conversion), hexadecimal points

Conversion Program:

// Input a decimal integer. The output float indicating the same memory layout is inline float i2f (int I) {float f = 0; assert (sizeof (int) = sizeof (float); memcpy (& f, & I, 4); return f;} inline double ll2d (long ll) {double d = 0; assert (sizeof (double) = sizeof (long); memcpy (& d, & ll, 8); return d ;}/ * Ask hovertree.com */

Application:

Int I =-1052770304; // This is the result of the disassembly. It is actually a float type, =-12.0 float f = i2f (I ); printf ("f = % f \ n", f); long ll = 0x4004000000000000L; // This is shown in the memory. The actual type is double 2.5 double d = ll2d (ll); printf ("d = % f \ n", d);/* why do you ask hovertree.com */

The principle is to copy memory data and then explain it with different data types.

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

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.