episode2

//it is very interesting,an excellect teacher,  I love it

1,why negative is indicated the way it is indicated

2,how float  is indicated

3,type conversion of negative integer type

4,type conversion between  float  and intergral type

----types

----negative denotation:why use the way that reverse all the bits and add 1 to represent negative dates.//very clear explain,very excellent teacher.

--take 7 for example, if use 1000 0111 as -7, than do the add operation between 7 and -7,the result is -14.
   0000 0111

+ 1000 0111

= 1000 1110

of course this does not work.

--we want 7 and -7 to get full 0,now firstly we try the result  full 1,because full 1 is easier to calculate than full 0. like

0000 0111

+ ???? ????

= 1111 1111

we can see what we need is

1111 1000

it it the reverse of 7:0000 0111,

--to get the result full 0, we need to add 1 to the current full 1,

1111 1111

+  0000 0001

=10000 0000     the1 in the result is overflow,and  does not count, so get 0,which is what we want.

therefore, the data we calculted should add 1 correponding to get the full 0.

which is  1111 1000 + 1,

the above is why negative dates are indicated in its way: reverse all the bits(execpt the sigh bit) and add 1.

--char, short, int, long, type conversion

--unsigned type, the simplest way, follow the protocal, electronics does not care the lost bytes.

small bytes to big bytes, just copy to low bytes.

big bytes to small bytes, cut the high bytes,use the low bytes.

--signed type, render sign expansion

to keep the signed characteristic, with negative sign, all expanded bits should be 1.domino effect

1000 0111

0000 0000 0000 0000

1111 1111 1000 0111   domino effect

----float

float:

1bit(符号位)

8bits(指数位)

23bits(尾数位)

double:

1bit(符号位)

11bits(指数位)

52bits(尾数位)

4 bytes, 有2^32个映射能够表示 -2^31到2^31-1个数。

--float protocal: (符号s) 1.xxxxx *2^(exp-127)

1位符号位s,8位exp, 23位表示小数点后的数据.xxxx

对于exp,magnitude only, int 0-255, 这意味着指数的范围是-127到128

对于23位.xxxx, when all 1, means 1减去2的-23次方,是一个与1很接近的数。当这23位 all 1 再加上1后,这个float数据就变成一个能被2整除的数。

_______________

_关于取值范围

float的指数范围为-127~128,而double的指数范围为-1023~1024,并且指数位是按补码的形式来划分的。其中负指数决定了浮点数所能表达的绝对值最小的数;而正指数决定了浮点数所能表达的绝对值最大的数,也即决定了浮点数的取值范围。

float的范围为-2^128 ~ +2^128,也即-3.40E+38 ~ +3.40E+38;double的范围为-2^1024 ~ +2^1024,也即-1.79E+308 ~ +1.79E+308。

_关于精度: 就是小数点后能有多少位

float和double的精度是由尾数的位数来决定的。浮点数在内存中是按科学计数法来存储的,其整数部分始终是一个隐含着的“1”,由于它是不变的,故不能对精度造成影响。

float:2^23 = 8388608,一共七位,这意味着最多能有7位有效数字,但绝对能保证的为6位,也即float的精度为6~7位有效数字;double:2^52 = 4503599627370496 ,一共16位,其精度为15~16位。

__________________________________

--eg. 7

7.0 * 2^0

3.5 * 2^1

1.75*2^2

乘号左边范围是,1-1.9

乘号右边指数不能小于-127,否则type double love it .

----float and int , types conversion

--eg1,

int i =5;

float f =i;

cout<<f<<endl; //  f is printed 5.000000

--eg2,

int i = 37;

float f = *(flat*)&i;// f is a very very small thing, barely meaningful

--eg3,

float f=7.0;

short s = *(short*)&f;

for the 4 types of the float date, the pointer point at the highest byte address,thus the short date get the high two bytes.

编程范式 epesode2 negative values, float 精度的更多相关文章

  1. ReactiveX编程范式

    ReactiveX http://reactivex.io/ An API for asynchronous programmingwith observable streams The Observ ...

  2. 编程范式感想(一)——在C中进行对模板功能的实现

    最近一直在看网易公开课上的编程范式的公开课,斯坦福的教授讲的真的非常到位,感觉还是要好好学习下C还有汇编,熟悉下计算机的内存机制什么的. 大家都知道关于模板或者说范式的问题,基本在很多高级语言上都有实 ...

  3. 【编程范式】C语言1

    最近在网易公开课上看斯坦福大学的<编程范式>,外国人讲课思路就是清晰,上了几节课,感觉难度确实比我们普通大学大很多,但是却很有趣,让人能边学边想. 范式编程,交换两个数,利用 void * ...

  4. 编程范式:命令式编程(Imperative)、声明式编程(Declarative)和函数式编程(Functional)

    主要的编程范式有三种:命令式编程,声明式编程和函数式编程. 命令式编程: 命令式编程的主要思想是关注计算机执行的步骤,即一步一步告诉计算机先做什么再做什么. 比如:如果你想在一个数字集合 collec ...

  5. Linux Kernel C语言编程范式

    介绍 不同的编程语言具有不同的抽象原语(如下),有的原语抽象层次低,有的原语抽象层次高.其中函数式.DSL是这几年十分热门的编程语言概念. 过程式抽象原语:变量 对象式抽象原语:对象 函数式抽象原语: ...

  6. 冒号课堂 编程范式与OOP思想

    上篇:编程范式与编程语言 第1课 开班导言 第2课 重要范式 第3课 常用范式 第4课 重温范式 第5课 语言小谈 第6课 语言简评 下篇:抽象机制与对象范式 第7课 抽象封装 第8课 抽象接口 第9 ...

  7. Python3学习之路~6.1 编程范式:面向过程 VS 面向对象

    编程范式 编程是程序员用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程,一个程序是程序员为了得到一个任务结果而编写的一组指令的集合,正所谓条条大路通罗马,实现一个任务的方式有很多种 ...

  8. Edit Distance问题在两种编程范式下的求解

    本文已授权 [Coding博客](https://blog.coding.net) 转载 前言 Edit Distance,中文叫做编辑距离,在文本处理等领域是一个重要的问题,以下是摘自于百度百科的定 ...

  9. jQuery中的编程范式

    浏览器前端编程的面貌自2005年以来已经发生了深刻的变化,这并不简单的意味着出现了大量功能丰富的基础库,使得我们可以更加方便的编写业务代码,更重要的是我们看待前端技术的观念发生了重大转变,明确意识到了 ...

随机推荐

  1. Scalding初探之二:动手来做做小实验

    输入文件 Scalding既可以处理HDFS上的数据,也可以很方便地在本地运行处理一些test case便于debug,Source有好多种 1 TextLine(filename) TextLine ...

  2. Server ran out of threads to serve requests. Consider raising the ThreadsPerChild setting

    最近每天半夜,服务器都会出现崩掉的现象,pc  app 都不能正常使用 查看错误日志发现问题所在: [Wed Nov 09 08:07:28.651642 2016] [mpm_winnt:error ...

  3. iTunesConnect进行App转移

    最近有客户提出需求,要把发布的OEM应用转移到自己的账户下,查询未果,在网站上搜索,死活找不到对应的选项,这两天看之前提交的版本已经审核通过了,发现很容易的就找到了转移版本的地方. 仔细思量,应该是之 ...

  4. 给table行换色

    <script language="javascript"> //假设Table的ID为angel $("#angel tr").click(fun ...

  5. IAR for msp430 MDK中 warning: #223-D: function "xxx" declared implicitly 解决方法

    今天在EINT的范例里添加了一个函数,即eint.c中添加了一个datawrite()的函数,并在主函数main.c中调用,编译便警告 warning: #223-D: function " ...

  6. Python字典实现三级菜单

    ################################################ # Task Name: 三级菜单 # # Description:打印省.市.县三级菜单 # # 可 ...

  7. selenium多个窗口切换

    浏览器里面支持多窗口打开,例如这样: html里面写了: target="_blank" 造成新打开一个窗口,但是selenium不会自动跳转到新的串口,需要自己切换: # 你打开 ...

  8. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十一) 代码重构使用反射工厂解耦

    前言 自从此博客发表以及代码开源以来,得到了许多人的关注.也没许多吧,反正在我意料之外的.包括几位大牛帮我做订阅号推广,真的很感谢他们.另外,还有几个高手给我提了一些架构上的问题.其实本身这个项目是没 ...

  9. ./configure,make,make install的作用(转)

    这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤. ./configure是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不是需要CC或GCC ...

  10. [zz] be similar with和be similar to的区别

    http://wenda.tianya.cn/question/4cb13da080ee34c9 be similar to后边既可以加物主代词又可以加人,即:be similar to sth/sb ...