当前位置:网站首页>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
边栏推荐
- Jerry is the custom background specified by the currently used dial enable [chapter]
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- I want to say more about this communication failure
- Kill -9 system call used by PID to kill process
- 【Swoole系列2.1】先把Swoole跑起来
- 2019 Alibaba cluster dataset Usage Summary
- Jerry's updated equipment resource document [chapter]
- C language exchanges two numbers through pointers
- declval(指导函数返回值范例)
- 解读云原生技术
猜你喜欢
微信为什么使用 SQLite 保存聊天记录?
Jerry is the custom background specified by the currently used dial enable [chapter]
CSRF漏洞分析
面向程序员的精品开源字体
Open source and safe "song of ice and fire"
FMT open source self driving instrument | FMT middleware: a high real-time distributed log module Mlog
1700C - Helping the Nature
Windows连接Linux上安装的Redis
Recommend easy-to-use backstage management scaffolding, everyone open source
简单易用的PDF转SVG程序
随机推荐
Recommend easy-to-use backstage management scaffolding, everyone open source
Alibaba cloud international ECS cannot log in to the pagoda panel console
Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
Four processes of program operation
推荐好用的后台管理脚手架,人人开源
图片缩放中心
Why does wechat use SQLite to save chat records?
STM32+HC05串口蓝牙设计简易的蓝牙音箱
Five data structures of redis
POJ 2208 已知边四面体六个长度,计算体积
阿里云国际版ECS云服务器无法登录宝塔面板控制台
递归的方式
std::true_type和std::false_type
SQL优化问题的简述
2019 Alibaba cluster dataset Usage Summary
C语言高校实验室预约登记系统
Splay
随着MapReduce job实现去加重,多种输出文件夹
STM32+ENC28J60+UIP协议栈实现WEB服务器示例
2019阿里集群数据集使用总结