当前位置:网站首页>Binary representation of negative integers and floating point numbers
Binary representation of negative integers and floating point numbers
2022-07-28 16:57:00 【Watching the moon in the bamboo forest】
List of articles
Preface
For this code
public class hello {
public static void main(String[] args) {
int a = -17;
System.out.println(" Binary output "+Integer.toBinaryString(a));
int b = 17;
System.out.println(" Binary output "+Integer.toBinaryString(b));
}
}
Output result 
So I'm curious about the binary representation of negative integers and floating-point numbers .
Because of learning 《 Deep understanding of computer systems 》 This course , In chapter two 《 Expression and processing of information 》 I have come into contact with relevant knowledge , The representation of floating point numbers in computers , And the addition and subtraction of signed and unsigned integers . Therefore, it is hereby supplemented .
One 、 Binary representation of negative integers
1. Original code
The original code is the binary representation of the absolute value of the number . In this code ,-17 The original code of is 17 Binary system 10001,int Type of data takes up four bytes, that is 32 position , But omit the previous 0.
2. Inverse code
Inverse code is to reverse the original code by bits , Such as 1 Turn into 0,0 Turn into 1. In this code ,10001 The inverse of is 11111111111111111111111111101110.
3. Complement code
The complement is about to add one to the inverse . In this code ,11111111111111111111111111101110 Add 1 by 11111111111111111111111111101111. It is the binary expression of negative integer .
Two 、 Binary representation of floating-point numbers
1. The formula :

According to international standards IEEE 754, Any binary floating point number V It can be expressed in the following form :
(1) (-1)^s The sign bit , When s=0,V Is a positive number ; When s=1,V It's a negative number .
(2) mantissa M Represents a significant number , It's a binary decimal , Its scope is 1~2-ε perhaps 0 ~ 1-ε.
(3)2^E Indicates the index bit ,E It's a step code .
for example :
take float=1.25f Convert to binary .
s=0;M=1.25;E=2;
about float type . The first is the sign bit , Next 8 Bit is the order code part , The rest of the 23 Bit is the mantissa part .
1. First, convert the number into binary number .
First step :
Bounded by the decimal point , Divided into integer and decimal parts .
In this question, it is divided into 1 and 0.25 Two parts .
The second step :
The integer part is divided by two and the decimal part is multiplied by two .
The whole part is 1, The decimal part is 01.
The third step :
Combine integer and decimal parts . namely 1.01.
2. Convert binary decimals to IEEE Floating point standard format V
3. Index part : Actual index value 2 Add a ( Exponential offset ), about 32 For single precision floating-point numbers , The offset value is 127, therefore exponent The value is 127 + 2 = 129 , Binary representation as 10000001.
4. Effective word bit , Also called mantissa , namely 2. Binary in represents the decimal part of the value , namely 111101001, Make it up to 23 position , Or get fraction The position is expressed as :01000000000000000000000
5. result 0 10000001 01000000000000000000000.
2. Classification of floating point numbers ( Classify according to the order code )
1: Normalized values
This is the most common , When exp The value of is not all 1 Or not all of them 0 This is always the case . At this moment , The order code field is interpreted as a signed integer in the form of an offset , namely E=e-Bias,e Is an unsigned number ,Bias=(2 Of k Minus one power ) Minus one .(k Is the order code point , Determined by the type of the number , If such float It is also a single precision floating-point type , be k The value of is 8; Double precision floating point k The value of is 16.M The value of is 1+f.
2: Denormalized values
When the order code field is all 0 when , For denormalization . Order code value E=1-Bias, The value of the mantissa M=f, Is the value of the decimal field , Does not contain implied 1.
3: Special values
When the order codes are all 1 when , For this situation .
When the decimal fields are all 0 when , The value obtained is infinite , Positive and negative infinity depends on the sign bit s Value .
When the decimal field is non-zero , The result is called “NAN”, namely “Not a Number”.
3. Rounding of floating point numbers
The rounding of floating-point numbers has a directed even rounding , towards 0 Rounding and rounding up or down , In the face of different situations , They are probably the closest rounding method to the real value .
边栏推荐
- USB产品(FX3、CCG3PA)的调试方法
- Is smart park the trend of future development?
- asp.net大文件分块上传断点续传demo
- parseJson
- parseJson
- IM即时通讯开发优化提升连接成功率、速度等
- First day of QT study
- [learn slam from scratch] publish the coordinate system transformation relationship to topic TF
- LeetCode每日一练 —— 160. 相交链表
- Ansa secondary development - build ansa secondary development environment on Visual Studio code
猜你喜欢

Jsonarray traversal

Sort 3-select sort and merge sort (recursive implementation + non recursive implementation)

有趣的 Kotlin 0x08:What am I

【深度学习】:《PyTorch入门到项目实战》第六天:多层感知机(含代码)

WSL+Valgrind+Clion

Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints

Ansa secondary development - build ansa/meta secondary development environment on pycharm

阿里大哥教你如何正确认识关于标准IO缓冲区的问题

IM即时通讯软件开发网络请求成功率的优化

Debugging methods of USB products (fx3, ccg3pa)
随机推荐
Nowcode- learn to delete duplicate elements in the linked list (detailed explanation)
IM即时通讯软件开发网络请求成功率的优化
小程序:scroll-view默认滑倒最下面
Applet: scroll view slides to the bottom by default
Oracle system composition
我该如何理解工艺
Re13: read the paper gender and racial stereotype detection in legal opinion word embeddings
Interesting kotlin 0x06:list minus list
ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)
Implementation of transfer business
parseJson
Efficiency comparison of three methods for obtaining timestamp
Learn ABAQUS script programming script in an hour
Understanding of asmlinkage
Installation of QT learning
Epoll horizontal departure, which edge triggers
Using pyqt to design gui in ABAQUS
Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
做题笔记5(有序数组的平方)
asp.net大文件分块上传断点续传demo