当前位置:网站首页>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 ![]()
边栏推荐
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- TOP命令详解
- 287. 寻找重复数
- UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
- Windows连接Linux上安装的Redis
- 微信为什么使用 SQLite 保存聊天记录?
- 最新财报发布+天猫618双榜第一,耐克蓄力领跑下个50年
- Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
- FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
- 2019 Alibaba cluster dataset Usage Summary
猜你喜欢

Interesting - questions about undefined

Windows连接Linux上安装的Redis

从交互模型中蒸馏知识!中科大&美团提出VIRT,兼具双塔模型的效率和交互模型的性能,在文本匹配上实现性能和效率的平衡!...

1700C - Helping the Nature

Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day

微信为什么使用 SQLite 保存聊天记录?

Grafana 9.0 正式发布!堪称最强!

推荐好用的后台管理脚手架,人人开源
![[swoole series 2.1] run the swoole first](/img/cd/88abf7e83e9d9d416051b33263690b.png)
[swoole series 2.1] run the swoole first

Compilation Principle -- C language implementation of prediction table
随机推荐
【Android】Kotlin代码编写规范化文档
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
Interesting - questions about undefined
Maixll-Dock 摄像头使用
编译原理——自上而下分析与递归下降分析构造(笔记)
Easy to use PDF to SVG program
ADB common commands
On time and parameter selection of asemi rectifier bridge db207
容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
30 minutes to understand PCA principal component analysis
2022 Summer Project Training (I)
Interview shock 62: what are the precautions for group by?
Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
小程序在产业互联网中的作用
Windows连接Linux上安装的Redis
Four processes of program operation
std::true_ Type and std:: false_ type
STM32+ESP8266+MQTT协议连接OneNet物联网平台
Implementation of queue
具体说明 Flume介绍、安装和配置
