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 ...
随机推荐
- 划分树---Feed the dogs
POJ 2761 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to fee ...
- mfc110.dll丢失,解决方法
mfc110.dll下载_附文件使用方法 mfc110.dll是存放在windows系统中的一个重要dll文件,缺少它可能会造成部分软件或游戏无法正常运行.当系统提示“没有找到mfc110.dll”或 ...
- C#中的接口实现多态
我们都知道虚方法实现多态,抽象方法实现多态等,我们今天来看看如何使用接口实现多态 1.首先我们先要来了解了解什么是接口,它存在的意识 01.接口就是为了约束方法的格式(参数和返回值类型)而存在的 02 ...
- Follow me to learn how to use mvc template
Introduction After having gone through many project: Project A Project B Project C I start to write ...
- css导航栏
几个导航栏也算对学过知识的回顾,总有新的收获,下面是学习过程中敲的代码: <!DOCTYPE HTML> <html> <head> <title>&l ...
- IE浏览器中ajax使用缓存数据的问题
今天做了一个小功能:点击鼠标实时更新系统时间,采用ajax,过程很顺利,没遇到啥差错,谷歌,火狐,欧鹏一律通过,怀着忐忑的心情点开了IE8,果然,IE要对得起前端杀手的称号:更新不了时间. 查了一下这 ...
- 高清SDI编码器|上海视涛科技
SDI编码器(E500)简介 SDI编码器(E500)是上海视涛科技出品的高性能SDI编码产品.该SDI编码器是上海视涛电子完全自主研发,并适用于各种SDI信号的编码采集及网络传输的专用硬件设备.可兼 ...
- Atitit.HTTP 代理原理及实现 正向代理与反向代理attilax总结
Atitit.HTTP 代理原理及实现 正向代理与反向代理attilax总结 1. 普通代理1 1.1.1. 普通代理2 2. 隧道代理3 3. 反向代理 4 4. 正向代理也可以使用apache实现 ...
- android 打包错误
打包时报如下错误: Export aborted because fatal lint errors were found. These are listed in the Lint View. Ei ...
- iOS扫一扫功能开发
之前很多二维码扫描都是基于zxing做的,但是zxing用起来真的很麻烦,又一直不更新.随着iOS6退出历史舞台,终于可以使用iOS7以后,用系统的AVFoundation做的二维码扫描器了. 初始化 ...