function [ binary,decimal ] = num2binary16( number )
function [ binary,decimal ] = num2binary16( number )
%The IEEE 754 standard specifies a binary16 as having the following format:
%Sign bit: 1 bit
%Exponent width: 5 bits
%Significand precision: 11 bits (10 explicitly stored)
%S EEEEE MMMMMMMMMM
%INPUT: number is a random precision number
%OUTPUT : var binary is a 2's string of the binary16
% var decimail is the value of the number in decimal
%Author :Yang Li .
%Email: yangli0534@gmail.com
%Data:20150126
if real(number) >= 2^14
error('beyond the maximum :-2^14--+2^24');
end
S=number<0 ;
E=0;
M=abs(number);
while(M>=2 || M<1 )
if(M>=2)
E=E+1;
M=M/2;
else
E=E-1;
M=M*2;
end
end
M=round((M-1)*2^10) ;
number1=(-1)^S*(2^ E )*(1+M/2^10);
% binary=strcat(num2str(S),num2str(E),num2str(M))
E =E+15;
binary=strcat(num2str(S),dec2bin(E,5), dec2bin(M,10)) ;
sReal=(str2num(binary(1)));
eReal =-15;
for i=2:6
eReal=eReal+str2num(binary(i))*2^(6-i);
end
% eReal=eReal*(-1)^str2num(binary(2));
mReal = 0;
for i=7:16
mReal=mReal+str2num(binary(i))*2^(16-i);
end
numberReal=(-1)^sReal*2^eReal*(1+mReal/2^10);
err=num2str(abs(number-numberReal));
decimal=numberReal;
% disp(['the origin data is : ',num2str(number)]);
% disp(['the float format is : ',binary]);
% disp(['so ,there is a error :',num2str(abs(number-numberReal))]);
end
function [ binary,decimal ] = num2binary16( number )的更多相关文章
- oracle的decimal和number的对比
Oracle只是在语法上支持decimal类型,但是在底层实际上它就是number类型,支持decimal类型是为了能把数据从Oracle数据库移到其他数据库中(如DB2等). 因为decimal在O ...
- Oracle/MySQL decimal/int/number 转字符串
有时客户需要流水数据,当导出为excel的时候,客户编号等很长数字的栏位,被excel变成科学记数法,无法正常查看. 因此,需要将Oracle/MySQL中的decimal/int 转 varchar ...
- **611. Valid Triangle Number three pointer O(n^3) -> square(binary search larget number smaller than target)
Given an array consists of non-negative integers, your task is to count the number of triplets chose ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
- General Decimal Arithmetic 浮点算法
General Decimal Arithmetic http://speleotrove.com/decimal/ General Decimal Arithmetic [ FAQ | Decima ...
- Convertion of grey code and binary 格雷码和二进制数之间的转换
以下转换代码摘自维基百科 Wikipedia: /* The purpose of this function is to convert an unsigned binary number to r ...
- UVa 575 Skew Binary 歪斜二进制
呵呵,这个翻译还是很直白的嘛,大家意会就好. 第一次看到这个高大上题目还是有点小害怕的,还好题没有做过深的文章. 只要按照规则转化成十进制就好了,而且题目本身也说了最大不超过一个int的范围(2^31 ...
- General Purpose Hash Function Algorithms
General Purpose Hash Function Algorithms post@: http://www.partow.net/programming/hashfunctions/inde ...
- Friendly number
Friendly number Long numbers can be made to look nicer, so let’s write some code to do just that. Yo ...
随机推荐
- C#中弹出文件选择窗体和判断是否下载提示窗体的源码
1.创建一个window窗体
- javascript类的理解和使用
距离上次写博客已经过去好几个月了,现在手里的项目正好都结束了,闲暇之后开始理一下开发中一些问题,这次说一下javascript当中的类,可能很多人对于写惯了前台页面效果的coder来说,对于javas ...
- Ubuntu配置任意版本的apt-get镜像
我们知道,迄今为止,Ubuntu已有多个发行版,如11.04.11.10,以至于现在最新的16.*.而我们平常通过apt-get来安装软件,如果OS版本不同,那么镜像源的配置就不同,否则就会出现找不到 ...
- C语言范例学习02
第二章 指针 算是重点吧,这也是C语言的特色啊,直接访问物理存储. 重点: 指针就是一个存放它指向变量地址的变量,好绕口. 区分*在定义是与引用是的作用. 区分*.&的不同. 指针 ...
- flask-uploads扩展的使用笔记
涉及的flask扩展 flask-uploads flask的一个文件上传扩展, 提供了UploadSet这个概念 flask-wtf(中文) 很强大的表单的扩展 flask-bootstrap bo ...
- 多准则决策模型-TOPSIS方法
多准则决策–Multiple Criteria Decision Making 多准则决策–Multiple Criteria Decision Making 多准则决策是指在具有相互冲突.不可共度的 ...
- Android SDK Tools和Android SDK Platform-tools
SDK Platform 可以理解为版本,因此有 SDK Platform 7,SDK Platform 8等等Android SDK Tools 是各个版本都可通用的工具文件夹,里面有draw9pa ...
- es配置说明
cluster代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的.es的一个概念就是去中心化,字面上理解就是无中心节点,这是对于集群外部来 ...
- SQL 语句日期用法及函数
SQL 语句日期用法及函数 --DAY().MONTH().YEAR()——返回指定日期的天数.月数.年数:select day(cl_s_time) as '日' from class --返回天 ...
- atitit.mp4 视频文件多媒体格式结构详解
atitit.mp4 视频文件多媒体格式结构详解 1. 一.基本概念1 2. MP4文件概述2 3. mp4是由一个个“box”组成的,2 4. 典型简化mp43 5. Fragments5 6. r ...