当前位置:网站首页>Logical operation bit operation
Logical operation bit operation
2022-06-13 01:21:00 【Zhao_| adult】
List of articles
1、 Original code 、 Inverse code 、 Complement code 、 Shift the code
Original code 、 Inverse code 、 Complement code
- Positive numbers : The original code of a positive number 、 Inverse code 、 The complement is the same
- negative :
- Original code : The highest bit represents the sign bit , The negative sign bit is 1, The sign bit of a positive number is 0;
- Inverse code : The inverse of a negative number is based on its original code , The sign bits remain the same , The rest of the bits are reversed .
- Complement code : Complement code = Inverse code +1; Sign bits can be carried .
- Shift the code : On the basis of complement Sign bit inversion . Code shift can only be used to represent integers , Cannot represent decimal
- Replace the complement code with the original code : It is the same as converting the original code to the complement :–> Inverse code +1;
2、 Binary system 、 octal 、 Decimal system 、 Conversion between hexadecimals
Binary system 、 octal 、 Decimal system 、 Conversion between hexadecimals
3、 Floating point decimal conversion
Floating point decimal conversion
4、 Negative binary conversion
5. Logical operations
What is true ? : All nonzero values are true ;
What is false ?: 0 On behalf of false ;
1. Logic and &&
If and only if two operands are true ( Nonzero ) The result is true when ;
int x=100;
int y=50;
cout<<(x&&y)<<endl; //1
int x=100;
int y=0;
cout<<(x&&y)<<endl; //0
2. Logic or ||
As long as one of the two objects is true ( Nonzero ) That's true ;
int x=100;
int y=0;
cout<<(x||y)<<endl; //1
int x=0;
int y=0;
cout<<(x||y)<<endl; //0
3. Logic is not !
Reverses the value of the operand and returns ;
** Not 0 Take the opposite ⇒ 0; 0 Take the opposite ⇒ 1; **
int x=100;
cout<<(!x)<<endl; //0
int x=0;
cout<<(!x)<<endl; //1
The value here is negative And According to the not Is different , According to the not Need to be converted to Binary system , Then perform bit wise inversion ;
6. An operation
Convert it to Binary system It's going on An operation ;
1. Bit and &
35: 0 0 1 0 0 0 1 1
47: 0 0 1 0 1 1 1 1
&
————————————————————
35: 0 0 1 0 0 0 1 1
int x=35;
int y=47;
cout<<(x&y)<<endl; //35
2. Bit or |
35: 0 0 1 0 0 0 1 1
47: 0 0 1 0 1 1 1 1
|
————————————————————
47: 0 0 1 0 1 1 1 1
int x=35;
int y=47;
cout<<(x|y)<<endl; //47
3. Bit inversion ~
35: 0 0 1 0 0 0 1 1
~
————————————————————
92: 1 1 0 1 1 1 0 0 // The first bit is the sign bit
int x=35;
cout<<(!x)<<endl; // -36
As can be seen from the above 35 The output of the program is the same as The result of bitwise negation is inconsistent ?
Because negative numbers are usually used in calculations Complement code Express : So we should convert the inverse result into Complement code
35: 0 0 1 0 0 0 1 1
~
————————————————————
92: 1 1 0 1 1 1 0 0 // Original code
1 0 1 0 0 0 1 1 // Inverse code : The sign bits remain the same , The rest of the bits are reversed
+1
————————————————————
-36: 1 0 1 0 0 1 0 0 // The first bit is the sign bit
4. Bit exclusive or ^
Take the same 0 , The similarities and differences are 1;
35: 0 0 1 0 0 0 1 1
47: 0 0 1 0 1 1 1 1
^
————————————————————
12: 0 0 0 0 1 1 0 0
int x=35;
int y=47;
cout<<(x^y)<<endl; // 12
边栏推荐
- [Latex] 插入圖片
- MySQL exception: com mysql. jdbc. PacketTooBigException: Packet for query is too large(4223215 > 4194304)
- np.concatenate中axis的理解
- ArrayList underlying source code
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of vrsi, bbiboll, WR, bias and RSI indicators
- Summary of various installation methods of Lab View
- September 3, 2021 visual notes
- The second round of mesa
- Install pycharm process
- Leetcode find duplicates
猜你喜欢

HashSet underlying source code

Summary of various installation methods of Lab View

Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing

Database query user mailbox

How does Apple add QQ email?

Go JWT learning summary

Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier

MySQL connection query

Leetcode-19- delete the penultimate node of the linked list (medium)

The tle4253gs is a monolithic integrated low dropout tracking regulator in a small pg-dso-8 package.
随机推荐
Transaction characteristics and isolation levels
Rasa对话机器人之HelpDesk (三)
五篇经典好文,值得一看(2)
Minimum spanning tree problem
Key point detection data preparation and model design based on u-net Network -- detection model of four key points of industrial components
Jenkins continuous integration operation
Summary of various installation methods of Lab View
【斯坦福計網CS144項目】Lab1: StreamReassembler
MySQL exception: com mysql. jdbc. PacketTooBigException: Packet for query is too large(4223215 > 4194304)
工作与生活
Calculate sentence confusion ppl using Bert and gpt-2
spiral matrix visit Search a 2D Matrix
Leetcode question brushing 04 string
Downloading wiki corpus and aligning with multilingual wikis
spiral matrix visit Search a 2D Matrix
Continue when the condition is not asked, execute the parameter you compare
DFS and BFS notes (II): depth first search (implemented in C language)
Status of the thread
【斯坦福计网CS144项目】Lab1: StreamReassembler
Traditional machine learning classification model predicts the rise and fall of stock prices under more than 40 indicators