简体   繁体   English

内存(位)如何在 C 编程中工作

[英]How does memory(Bits) work in C Programming

Please explain this paragraph:请解释这一段:

Floating point numbers in C use IEEE 754 encoding. C 中的浮点数使用 IEEE 754 编码。

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.单精度 (float) 为您提供 23 位有效位、8 位指数位和 1 个符号位。

Double precision (double) gives you 52 bits of significant, 11 bits of exponent, and 1 sign bit.双精度 (double) 为您提供 52 位有效位、11 位指数位和 1 个符号位。

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.我最近开始用“C”编码,我学习了程序如何工作的所有数据结构。但是当我看到这一段时,我一个字都听不懂。

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.位是“开/关”开关,编码为 0 或 1。您也可以将其视为布尔值、True 或 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.对于浮点数,您有 23 位,因此您可以表示从 2^-23 到 1-2^-23 的任何内容。

The exponent also gives you powers of 2 ranging from (2^-126,2^127).指数还为您提供 2 的幂,范围为 (2^-126,2^127)。

Put everything together to get your float: (sign)(1+significant)2^(exponent)把所有东西放在一起得到你的浮点数:(符号)(1+显着)2^(指数)

Not all numbers can be exactly represented with powers of 2. Hence your machine approximates numbers like 0.1.并非所有数字都可以用 2 的幂精确表示。因此,您的机器近似于 0.1 之类的数字。

floats require 32 bits while doubles require 64 bits.浮点数需要 32 位,而双精度数需要 64 位。

Below is a concise article on IEEE floating points which should make things clearer: https://www.doc.ic.ac.uk/~eedwards/compsys/float/下面是一篇关于 IEEE 浮点的简明文章,它应该让事情更清楚: https : //www.doc.ic.ac.uk/~eedwards/compsys/float/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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