当前位置:网站首页>Blue Bridge Cup real question: one question with clear code, master three codes
Blue Bridge Cup real question: one question with clear code, master three codes
2022-07-06 18:19:00 【Py Xiaozheng】
Distance Blue Bridge Cup 56 God
The purpose of learning algorithm is to improve yourself
Thank a station for explaining the three codes Portal Original code Inverse code Complement code _ Bili, Bili _bilibili
Problem analysis : Many friends must be like Xiao Zheng Yes Explanation of the title stem : give Bytes as the value of a signed integer Don't understand at the beginning Why there are negative numbers ? For Xiaobai like Xiao Zheng , One byte, eight bits , The range of data represented [00000000,11111111] namely [0,255] Where did the negative number come from ?
Actually The above understanding is based on Unsigned data , actually , There is another kind of numerical data called Signed data .
There are three representations of signed data : Original code , Inverse code , Complement code
As long as you know the original code The latter two codes can be easily solved
8 Bit source code highest 0 A positive sign ,1 A minus sign The range of the last seven digits is [0,127]
therefore 8 Range of bit source code [-127,127] So there are two steps to determine the original code of a number :1: The sign determines the highest position 2: The absolute value of the number determines the last seven digits
Understand the original code The inverse code is easy to understand : The inverse code is based on the original code , Except for the highest position ( Sign bit ), The rest is reversed
Understand the inverse code Complement is easy to understand : Complement is based on inverse On the basis of irony +1
And these three codes , Complement is the most important Because in the computer system , All values are represented and stored by complements .
So the following focuses on the method of calculating complement ( This question is also based on complement )
First study negative numbers :
for instance : seek -1 Complement So we know -1 The original code of is 10000001
that -1 The inverse of is 11111110 that -1 The complement of is 11111111
It's that simple . Then for negative numbers [-127,-1] Can follow the above similar requirements -1 The method of calculation
And then to -128, We Regulations Its complement is 10000000
Then study positive numbers :
A complement to a positive number = The inverse of a positive number = The original code of a positive number Sum up 8 The representation range of bit complement [-128,127]
therefore , After knowing the three codes ( The most important thing is complement ), Return to the topic , Right now Bytes as the value of a signed integer Is the concept of clear ? In fact, let's find the complement of each integer
Each line of Chinese characters has 32 Bytes make up ,16*16 The pixel : a line 2 Bytes , A byte 8 position , form 16 That's ok
So print it out : So the question is what is the power of nine ?
s="""4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0
16 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 16
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0
0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4
4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64
16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128
0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0
2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0
1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0
0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0"""
a=s.split('\n')
dict={}
def reverse(str):
ans=''
for i in str:
ans+='0' if int(i)==1 else '1'
return ans
for j in range(-128,128):
if j>=0:
dict[j]=(8-len(bin(j)[2:]))*'0'+bin(j)[2:]
elif j==-128:
dict[j]='10000000'
else:
tmp=reverse((7-len(bin(abs(j))[2:]))*'0'+bin(abs(j))[2:])# Except for sign bit negation
tmp_add=bin(int(tmp,2)+1)[2:]#+1
dict[j]='1'+(7-len(tmp_add))*'0'+tmp_add
for i in a:
tmp=list(map(int,i.split()))
start=0#end=31
while start<=30:
s=dict[tmp[start]]+dict[tmp[start+1]]
print(s)
start+=2
print('\n')
Because the length is too long , Just put one ‘ Nine ’ Okay , Specifically, you can run the code by yourself
I'm Xiao Zheng Is running to love Go to the mountains and seas
边栏推荐
- Introduction to the usage of model view delegate principal-agent mechanism in QT
- node の SQLite
- 287. 寻找重复数
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
- Coco2017 dataset usage (brief introduction)
- 解读云原生技术
- Jielizhi obtains the currently used dial information [chapter]
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
- Interview shock 62: what are the precautions for group by?
- Rb157-asemi rectifier bridge RB157
猜你喜欢
阿里云国际版ECS云服务器无法登录宝塔面板控制台
Grafana 9.0 is officially released! It's the strongest!
递归的方式
传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
STM32按键状态机2——状态简化与增加长按功能
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design
2019阿里集群数据集使用总结
Olivetin can safely run shell commands on Web pages (Part 1)
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Declval (example of return value of guidance function)
随机推荐
node の SQLite
Windows connects redis installed on Linux
287. 寻找重复数
【剑指 Offer】 60. n个骰子的点数
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
Top command details
Jerry's watch reading setting status [chapter]
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
Kill -9 system call used by PID to kill process
ADB common commands
MarkDown语法——更好地写博客
declval(指导函数返回值范例)
Grafana 9.0 is officially released! It's the strongest!
【LeetCode第 300 场周赛】
随着MapReduce job实现去加重,多种输出文件夹
30 minutes to understand PCA principal component analysis
CSRF漏洞分析
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
小程序在产业互联网中的作用