当前位置:网站首页>Advanced data storage
Advanced data storage
2022-06-12 01:04:00 【anyway33】
One 、.C Common mistakes in language :
1. Compile error ( There are syntax errors in the code phase written , Or compile the wrong code , If the return value is missing , Double click the error prompt to jump to the error location )
2. link error , No, Reference header file or library function , Or the function or variable you created is undefined , Such as : Unexplained external symbols ...... ( Source file test.c→ compile → link →test.exe Executable program , Double click the error prompt and there is no response , Should use the ctrl+F Search the error reporting part , Or directly find the wrong part according to the error report )
Neither of the first two works , And there will be an error message , The naked eye can make mistakes , Easier to find and correct .
3. An error occurred while running ( It is necessary to solve the problem by debugging ), For example, an endless loop causes stack overflow
4. Wrong answer , The result is not correct .
Two 、 Original code 、 Inverse code 、 Complement code
Inverse code 、 The meaning of complement :
In the computer CPU Only the addition processor , Processing 1-1 Time is to turn it into 1+(-1) To deal with the .
for example char Type of 1-1:
1 The binary of is -0000 0001;-1 The binary of is -1000 0001;
stay CPU Middle computation 1+(-1) The result is 1000 0010 yes -2 The original code of , obviously 1+(-1)!=-2;
So after scientists' research , Evolved the inverse code 、 Complement operation .
First ,
A positive number 、 back 、 The complement is the same .
The inverse code of a negative number is that the original code negates the binary data bits , The sign bits remain the same , Get the inverse ; And then add the inverse code value +1, Get the complement .
( There are two ways to get the original code by complement .1. First on the complement value -1, Get the inverse , Then reverse the binary data bits of the inverse code , The sign bits remain the same , The final result is the complement 2. Reverse the complement binary data bit , The sign bits remain the same , And then on the numerical value +1, You can get the original code )
that 1-1 The operation of is :
1 Original , back , The complements are all 0000 0001;
-1 The original code of :1000 0001
Inverse code :1111 1110
Complement code :1111 1111
In the operation process of the system, its complement is calculated :
namely 0000 0001 +1111 1111=1 0000 0000, because char The type size is 1 Bytes ,8 A bit , The excess high byte bits will be rounded off , The end result is 0000 0000 , yes 0 Complement , Obviously the result is correct . The above is the inverse code 、 The necessity of complement .
3、 ... and 、 Big and small bytes
Big endian byte : The high byte bits are stored at the low address , The low byte bits are stored at the high address
Small byte : The high byte bits are stored at the high address , The low byte bits are stored at the low address
In the memory window of the system ( The default is 16 Base display , One bit is a hexadecimal number , Occupy 4 A bit , Two hexadecimal bits represent a byte ) Middle is the small end byte display , And the default , From left to right is the low address to the high address . So the low byte bits are displayed on the left , The high byte bits are shown on the right .
How to determine whether a compiler displays large end bytes or small end bytes ?
int check_sys()
{
int a = 1;
return *(char*)&a;
}
int main()
{
int ret = check_sys();
if (ret == 1)
{
printf(" The small end \n");
}
else
{
printf(" Big end \n");
}
, Use one char Type a pointer , Part of the interview ( Access starts at a low address ) The low address part of the number , If the low address part is the high byte part , It proves that the compiler is a big endian display ; If the low address part is loaded with low bytes , It proves that the compiler is a small end byte display .
Four 、 Forced conversion ()
int a=2;
char *p=(char*)&a;------ take int The type pointer is forcibly converted to char Type a pointer , In addition to type changes , Other sizes and the like have not changed , There will be no memory leaks , Because the pointer size is determined by the compiler , It's usually 4 or 8 Bytes .
5、 ... and 、%u,%d And integer lift
signed char b = -1;
unsigned char c = -1;
// //10000000000000000000000000000001
// //11111111111111111111111111111110
// //11111111111111111111111111111111
// //11111111 - c
// //00000000000000000000000011111111
printf("a=%d,b=%d,c=%d", a, b, c);
// //-1 -1 255
// // When we print a When , To have an integer lift
// // Printed is a signed number
// return 0;
//}
in
// //printf("%u\n", ch);//%u Is to print unsigned numbers , What you want me to print must be an unsigned number , Not an unsigned number , I also think it's an unsigned number
// printf("%d\n", ch);//%d Is the signed number printed , What you want me to print must be a signed number , Not a signed number , I also think it's a signed number
Then the result of this problem is , The first two types are upgraded during printing , But because it is a signed number , Integer type promotes the sign bit , After the complement integer is raised, it is converted back to the original code , The result remains the same .
the latter unsigned char c=-1; Because it is first defined as an unsigned number , The complement is 1111 1111, The default is positive , Then its original code 、 Inverse code 、 The complements are all 1111 1111, And unsigned in integer Promotion , The additional bit on the left is 0, therefore unsigned char c=-1; After being defined as an unsigned number , When printing, the integer is improved , The result of printing is 255.
So the print result of this question is -1 -1 255
边栏推荐
- 基于.NetCore开发博客项目 StarBlog - (11) 实现访问统计
- websocket服务器实战
- KV storage separation principle and performance evaluation of nebula graph
- Global and Chinese maleic anhydride polypropylene industry investment analysis and prospect trend forecast report 2022 Edition
- 2022 edition of global and Chinese hexamethylene chloride industry dynamic research and investment prospect forecast report
- [answer] business use cases and system use cases are mixed together
- Chapter V - Fund professional ethics
- Sword finger offer 09 Implementing queues with two stacks
- Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
- Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security
猜你喜欢

Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform

System. Commandline option

Crawler case 05 - parsing websites using XPath

打造Flutter高性能富文本编辑器——渲染篇

be based on. NETCORE development blog project starblog - (11) access statistics

Before applying data warehouse ODBC, you need to understand these problems first

Flowable workflow

模块八-设计消息队列存储消息数据的 MySQL 表格

Comparison of OpenCV basic codes of ros2 foxy~galactic~humble

Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
随机推荐
Chapter V - Fund professional ethics
Introduction to semantic vector retrieval
QApplication a (argc, argv) and exec() in the main function of QT getting started
Nat. Comm. | 超算+AI: 为天然产物生物合成路线规划提供导航
Why are the values of ordereddict not equal- Why are the values of an OrderedDict not equal?
Lambda quick start
Verification code is the natural enemy of automation? Let's see how Ali P7 solved it
Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security
LabVIEW Arduino electronic weighing system (project Part-1)
Lambda intermediate operation limit
Global and Chinese chromatographic silica gel resin industry research and investment direction forecast report 2022 Edition
Xiaomu's interesting PWN
Comparison of OpenCV basic codes of ros2 foxy~galactic~humble
Low code platform design exploration, how to better empower developers
DDD exaggeration, Eric Evans made a bad start
人们对于产业互联网的这样一种认识的转变,并不是一蹴而就的
Lambda中间操作limit
2022 edition of global and Chinese high purity silicon carbide powder operation research and investment strategy analysis report
基于.NetCore开发博客项目 StarBlog - (11) 实现访问统计
Lambda中间操作sorted