简体   繁体   中英

How does memory(Bits) work in C Programming

Please explain this paragraph:

Floating point numbers in C use IEEE 754 encoding.

This type of encoding uses a sign, a significant, and an exponent.

Because of this encoding, many numbers will have small changes to allow them to be stored.

Also, the number of significant digits can change slightly since it is a binary representation, not a decimal one.

Single precision (float) gives you 23 bits of significant, 8 bits of exponent, and 1 sign bit.

Double precision (double) gives you 52 bits of significant, 11 bits of exponent, and 1 sign bit.

I started coding in "C" recently i learned all the data structures how programs work and all.But when i saw this paragraph i didn't understand a word.

What is significant,exponent,bits.?

How does a variable,float,double store the values,how much space is required and where are they stored.

A bit is an "on/off" switch, encoded as 0 or 1. You can also think of it as a boolean, True or False.

The sign bit tells you if the float is positive or negitive.

The significant, also known as the Mantissa, gives you negative powers of two. For a float, you have 23 bits, so you can represent anything from 2^-23 up to 1-2^-23.

The exponent also gives you powers of 2 ranging from (2^-126,2^127).

Put everything together to get your float: (sign)(1+significant)2^(exponent)

Not all numbers can be exactly represented with powers of 2. Hence your machine approximates numbers like 0.1.

floats require 32 bits while doubles require 64 bits.

Below is a concise article on IEEE floating points which should make things clearer: https://www.doc.ic.ac.uk/~eedwards/compsys/float/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM