当前位置:网站首页>【11】 Binary code: "holding two roller handcuffs, crying out for hot hot hot"?
【11】 Binary code: "holding two roller handcuffs, crying out for hot hot hot"?
2022-07-27 06:53:00 【As bright as noon】
【 The principle of computer organization 】 Learning notes —— General catalogue
【11】 Binary code :“ Hold two Kunjin handcuffs , I cried out in my mouth ”?
- Recommended reading :《 code : Language hidden behind computer hardware and software 》
introduction
One 、 Understand binary “ On the two into one ”
Binary conversion 10 Base number : 0011【 Binary number 】, 0×23+0×22+1×21+1×20=3【0011 Corresponding decimal number 】
10 Turn into the system 2 Base number 【 Short division 】
- such as , We want to 13 This decimal number , Convert to binary by short division , You need to go through the following steps : therefore , The corresponding binary number , Namely 1101.

- such as , We want to 13 This decimal number , Convert to binary by short division , You need to go through the following steps : therefore , The corresponding binary number , Namely 1101.
Original code notation
- Positive numbers :0011【 representative 3, First place 0 For a positive number 】
- negative :1011【 representative -3, First place 1 It's a negative number 】
- problem :1000 and 0000 All represent 0, wasted 1 Number
extraction Complement code 【 The first is 1 when , It's a negative number , To 10 Base time , Put a minus sign on the far left 】
- example : One 4 Binary complement value of bit 1011, Convert to decimal , Namely −1×23+0×22+1×21+1×20
- The method of finding decimal complement 【 Add... In reverse 1】: -5 Corresponding to a signed bit negative number 5(10000101)→ All bits except sign bits are negated (11111010)→ Add 00000001 by (`11111011)0【-5 The complement of is 11111011】
- Of course More important yes , Use a complement to show a negative number , Make our It's easy to add integers , There's no need to do anything special , Just add it as a normal binary , You can get the right results .

Two 、 Representation of a string , From coding to numbers
1、 ASCII code (American Standard Code for Information Interchange, American standard code for information exchange )
2、 Binary serialization saves more memory space than string representation 【 Integers 、 Representation of numeric values such as floating point numbers 】
We can see , maximal 32 An integer , Namely 2147483647. If it's expressed as an integer , It only needs 32 A bit means . But if you use strings to represent , Altogether 10 Characters , Use... For each character 8 A word of , Need to be whole 80 position . Compared with integer representation , Take up a lot more space .
That's why , A lot of times when we store data , It's binary serialization , Rather than simply passing data through CSV perhaps JSON, This text format is stored for serialization . Whether it's an integer or something , Floating point numbers are good , Using binary serialization will save a lot of space than storing text .
3、 introduce Unicode Character set
ASCII The code just means 128 Characters , It's enough at first . But as more and more people in different countries use computers , I want to express words like Chinese ,128 There are obviously not enough characters . therefore , Computer engineers began to show their own magic , Create a corresponding... For your country's language Character set (Charset) and Character encoding (Character Encoding).
Character set 【 A collection 】, It can represent a set of characters . such as “ chinese ” It's a character set , But it's not accurate to describe a character set like this . Want to be more precise , We can say ,“ The first edition 《 Xinhua dictionary 》 All the Chinese characters in it ”, This is a character set . such , We can know for sure , A character is not in this set . such as , What we say every day Unicode, It's actually a character set , Contains 150 Language 14 Ten thousand different characters .
Character encoding 【 A set of conversion rules 】, It is For these characters in the character set , How to 11 a dictionary expressed in binary . What we said above Unicode, You can use it UTF-8、UTF-16, Even UTF-32 To code , Store as binary . therefore , With Unicode, In fact, we can use more than UTF-8 A form of coding , We can also invent our own GT-32 code , For example, it's called Geek Time 32 Okay . As long as others know the coding rules , It can be transmitted normally 、 Show this code .
4、“ Hold two Kunjin handcuffs , I cried out in my mouth ” Why ?【 The code problem 】
The essence of garbled code : The encoding and decoding are inconsistent
summary 【 Key points of personal summary 】
Original code One of the most intuitive drawbacks of notation is ,0 It can be expressed in two different codes ,1000 representative 0, 0000 On behalf of 0.
use Complement code To represent negative numbers , Make it easy to add our integers , There's no need to do anything special , Just add it as a normal binary , You can get the right results .
Practical application of complement : Binary to decimal 【 Binary is negative 】; Decimal negative to binary 【 Add... In reverse 1】
Inverse code It is usually used to find the complement from the original code or the transition code from the complement to the original code .
- When the inverse code is positive with the original code , equally (0001 The opposite of 0001); When negative , The inverse code is the original code, except for the sign bit , Other bits are reversed .(1001 The opposite of 1110)
What we say every day Unicode, It's actually a character set , Contains 150 Language 14 Ten thousand different characters .
Character set (Charset): A character aggregate .
Character encoding (Character Encoding): A set of Characters and numbers Of Conversion or correspondence The rules .
Character encoding is for these characters in the character set , How to 11 a dictionary expressed in binary . What we said above Unicode, You can use it UTF-8、UTF-16, Even UTF-32 To code , Store as binary .
The problem of garbled code is actually The encoding and decoding are inconsistent The problem of
【 The principle of computer organization 】 Learning notes —— General catalogue
边栏推荐
- Tips - completely delete the files on the USB flash drive
- Where to connect with user-defined functions leads to slow queries
- 改善宝宝过敏就吃伊敏舒,azg与Aibeca爱楽倍佳携手守护中国宝宝成长
- QGIS series (1) -qgis (server APACHE) win10 installation
- Decorator functions and the use of class decorators
- 备忘录 @RestControllerAdvice与异常拦截类示例
- Recommended by the world's most technologically competent smart contract security audit company in 2022
- ArcGIS for JS API entry series
- 自己动手实现容器
- ES6的新特性(2)
猜你喜欢

MangoDB

Li Hongyi 2020 deep learning and human language processing dlhlp conditional generation by RNN and attention-p22

Shell -- conditional statements (if statements, case statements)

Detection and identification data set and yolov5 model of helmet reflective clothing

To improve the baby's allergy, take yiminshu. Azg and aibeca love la Beijia work together to protect the growth of Chinese babies

Webodm win10 installation tutorial (personal test)

Iptables firewall

Lamp -- source code compilation and installation

Pruning - quantification - turn to onnx Chinese series tutorials

Express接收请求参数
随机推荐
According to SQL, you must know and learn SQL (MySQL)
win10 添加虚拟网卡,配置op路由
Open source WebGIS related knowledge
Log in to Alibaba cloud server with a key
Sunflower popularizes Science in an all-round way to avoid loopholes for your remote control equipment in time
EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?
网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
FTX.US推出股票和ETF交易服务,让交易更透明
Detection and identification data set and yolov5 model of helmet reflective clothing
Go语言学习
DNS domain name resolution service
NAT(网络地址转换)
Project training experience 1
NFS简介和配置
Inventory of the world's six most technologically competent smart contract audit companies in 2022
Memo @restcontrolleradvice and exception interception class example
众多世界500强企业集聚第二届数博会,数字产业大幕即将开启!
keras-ocr实例测试
FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health
System security and Application