当前位置:网站首页>[dish of learning notes, dog learning C] first learn operators and original code, inverse code, complement code
[dish of learning notes, dog learning C] first learn operators and original code, inverse code, complement code
2022-07-21 03:14:00 【Jiang Junzhu】
List of articles
One 、 The operator
1. arithmetic operator
+ | Add |
---|---|
- | Subtraction |
* | Multiplication |
/ | division |
% | modulus / Remainder , Get the remainder |
2. Shift Operators
<< | Shift left operator |
---|---|
>> | Shift right operator |
The shift operator moves the binary digits
One int The memory occupied is 4 byte , so a The value of is expressed as :
00000000 00000000 00000000 00000
010
a Move one bit to the left , Auto add later 0,
00000000 00000000 00000000 00000
100
Then convert the binary into decimal , That is to say 4
3. Bit operators
& | Bitwise AND |
---|---|
| | Press bit or |
^ | Bitwise XOR |
4. Assignment operator
= += -= *= &= ^= |= >>= <<=
5. Monocular operators
! | Logical anti operation |
---|---|
- | It means negative |
+ | It means a positive value |
& | Address fetch |
sizeof | The type length of the operands ( In bytes ) |
~ | To reverse the binary of a number |
- - | In front of - -( First - -, After use ), After - -( First use , after - -) |
++ | In front of ++( First ++, After use ), After ++( First use , after ++) |
* | Indirect access operators ( Dereference operator ) |
( type ) | Cast |
Here is about ~ The operator
Code for ( This involves the original code 、 Inverse code 、 Knowledge of complement )
int main() {
//0 The binary value of is 00000000 00000000 00000000 00000000
//~ It's bitwise negation, so the result is 11111111 11111111 11111111 11111111
// An integer stored in memory is a complement
//-1 The original code of is 10000000 00000000 00000000 00000001, The first digit represents the sign ,0 just 1 negative
// Inverse code is to reverse the original code , have to 11111111 11111111 11111111 11111110, The sign bits remain the same
// Complement is to add one to the inverse code , have to 11111111 11111111 11111111 11111111
// The original and inverse complements of positive integers are the same
int a = 0;
printf("~a The value of is :%d\n", ~a);
return 0;
}
6. Relational operator
> | Greater than |
---|---|
>= | Greater than or equal to |
< | Less than |
<= | Less than or equal to |
7. Logical operators
&& | Logic and |
---|---|
|| | Logic or |
8. Conditional operators ( ternary operators )
epx1 ? epx2 : exp3
int main() {
// Conditional operator
int a = 1;
int b = 3;
int MAX = a>b ? a : b;
printf("MAX:%d\n", MAX);
return 0;
}
9. Comma expression
Comma expression , A comma separates a string of expressions , The comma expression is evaluated once from left to right 、 The result of the entire expression is the result of the last expression .
exp1, exp2, epx3, ...expN
10. Subscript references and function calls
[ ] | Subscript reference operator ( Common in arrays ) |
---|---|
() | Function call operator , When you call a function , After the function name () Is the function call operator |
Two 、 Original code 、 Inverse code 、 Complement code
In the computer , There are three ways to express signed numbers : Original code 、 Inverse and complement 1
Original code 、 Inverse code 、 Complement is binary , The first digit is used to indicate positive and negative ,0 It means that this is a positive number ,1 Indicates that this is a negative number , The next number is used to indicate the size of this number . Usually, the 8 The multiples of are a set of , because 1B( byte )=8(bit) position
, One bit represents a binary number . for instance :
7 | -7 | |
---|---|---|
Original code | 0000 0111 | 1000 0111 |
Inverse code | 0000 0111 | 1111 1000 |
Complement code | 0000 0111 | 1111 1001 |
The original code of a positive number 、 Inverse code 、 The complement is the same ;
The inverse code of a negative number is that the original code is reversed except for the sign bit , Complement is based on the obtained inverse code +1.
Operator details :【 Learning notes Dog learn C】 Explain operator
Another saying is , Only complement in the computer , There is no original code or reverse code . I didn't check the details , I guess it should be the original code 、 Anti code has disadvantages and is eliminated . ︎
边栏推荐
猜你喜欢
DOM——事件语法
【学习笔记之菜Dog学C】循环语句
Preparation of 5-FU / dex-g-pla nanoparticles /bsa agncs Pei nanoparticles /cu (DDC) 2 protein nanoparticles
Automatic saving function in LabVIEW
毕业季--各应用场景案例使用技术
2022-7-19 第八小组 顾宇佳 学习笔记 (this关键字和封装)
Millet college reported an error 503 when registering the gateway gateway with Nacos
多分类的风险评分数据实操,助您中小微业务稳人一步
Ctfshow web entry information collection WP (1-20) (detailed explanation)
【科学文献计量】中英文文献标题及摘要分词字数与频数统计与可视化
随机推荐
Apache Doris Binlog Load使用方法及示例
Matplotlib教程(一)【初识Matplotlib】
SQL optimization (x): association update
dom——操作文档树及其案例
【学习笔记之菜Dog学C】数据存储
Oracle按中文排序
Visual Studio 开发环境的配置
Jupyter notebook如何更换主题、更改字体大小?
mknod命令:创建设备文件
作为程序员的思考
easyExcel设置最后一行的样式【可以拓展为每一行】
win10如何实现电脑上文件共享访问
【学习笔记之菜Dog学C】初识常见关键字、#define定义常量和宏
蓝桥杯2020年第十一届国赛真题-天干地支
sklearn决策树(Decision Trees)模型
[scientific literature measurement] analysis and visualization of readability indicators of Chinese and English literature titles and abstracts
Implementation of fruit and vegetable mall management system based on SSM
A. Subtle Substring Subtraction
DOM——事件语法
webSocket学习与使用