当前位置:网站首页>Introduction of C language base conversion and original complement inverse code point operation
Introduction of C language base conversion and original complement inverse code point operation
2022-07-27 05:37:00 【I'm really not a second dimension】
Hexadecimal conversion
Reason for using base
- Because of the present CPU Only high and low levels can be recognized , Only binary data can be calculated
- Although binary data can be directly CPU Identify calculations , But it is not convenient to write and record , Because converting binary data into octal is to facilitate recording in documents
- because CPU The number of digits is increasing , from 8 Bit gradually developed to the present 64 position , Therefore, octal cannot meet the demand gradually , So we developed hexadecimal , However, due to historical reasons, octal cannot be completely eliminated
Hexadecimal conversion
1. Decimal to binary
Remainder method : use 2 Balance the data , Then continue to seek surplus from the business , Until Shang Wei 0 end , The remainder generated in this process is the binary of the data ( The reverse )
n%2==1\0
merchant %2 ==1\0
…
Until Shang Wei 0
The reverse order of the remainder is n Binary systemRight seeking method : From high to low , data -2^(n-1) If it's enough , So the first n Bit is 1, Otherwise, it would be 0, Until the data is reduced to 0
128 64 32 16 8 4 2 1
86(01010110)
72(01001000)
112(01110000)
176(10110000)
2. Binary to decimal
Everyone's 2^(n-1) Sum up
10010010 145
3. Binary to octal
Starting from the low , Every three binary bits corresponds to one octal
Binary system : 1 001 010 101 110
octal : 1 1 2 5 6
4. Binary to hexadecimal
Starting from the low , Every four binary bits corresponds to one hexadecimal
Binary system : 1 0010 1010 1110
Hexadecimal 1 2 A E
stay C In language , With 0 The first number is octal number 0x The first number is hexadecimal
%c 072
%o Display data in octal
%x Display data in hexadecimal
%#o %#x Display the prefix corresponding to the data
Original code 、 Inverse code 、 Complement code
Original code
Binary of data
Inverse code
Sign bit 1 It's a negative number 0 Positive number
The inverse code of a positive number is its original code
The inverse code of a negative number is its original code except for the sign bit , Other bits are inversed bit by bit
Complement code
The complement of a positive number is its original code
The complement of a negative number is its inverse +1
Be careful : All data in memory is stored in the form of complement
1、 Negative numbers are converted to binary
2、 The sign bits remain the same , The rest are inversed by position
3、 Inverse code +1 Get the complement
-127
Original code :1111 1111
Inverse code :1000 0000
Complement code :1000 0001
Complement to data
Unsigned complement is directly converted to decimal
The highest sign is 0, The description is positive , It is also directly converted to decimal
Signed and the highest bit is 1:
1、 Complement code -1 Get the inverse
2、 The sign bits remain the same , Other bits are inversed bit by bit to get the original code
3、 Convert the original code into decimal data
1111 1111 Complement code A signed
1111 1110 Inverse code
1000 0001 Original code
-1 Decimal system
Introduction to bitwise operators
A & B Press phase and There are false and false
00110010
11001010
--------
00000010 0x2
A | B Press phase or True and true
00110010
11001010
--------
11111010
~A Reverse by position
00110010
11001101
A ^ B Bitwise XOR Same as 0, Dissimilarity is 1
00110010 0x32
11001101 0xCA
--------
11111000 0xf8
A<<n hold A The complement of moves left n position , Discard the left and fill the right 0
0x32 << 3
00110010 0X32
10010000 0x90
A>>n hold A To the right n position , On the right side of the discarded , Fill in the sign on the left ( Not sign bit complement 0, It is a sign complement 1)
00110010 0X32
11110110
practice : Enter an integer , It's 4~7 Bit is set to 1010, Other bits cannot be changed
101101011 0111 0101 num
101101011 1010 0101 (num & ~(oxf<4)) | (0xA<<4)
000000000 1010 0000 0xA<<4
101101011 0000 0101 num & ~(oxf<4)
111111111 0000 1111 ~(oxf<4)
000000000 1111 0000 oxf<<4
000000000 0000 1111 oxf
边栏推荐
- 李宏毅机器学习组队学习打卡活动day04---深度学习介绍和反向传播机制
- 2021 Niuke multi school training camp 5 (question b)
- Differences and examples between internal classes and static internal classes
- Hi3516dv300 environment setup
- C语言进制转换以及原补反码位运算介绍
- 李宏毅机器学习组队学习打卡活动day03---误差和梯度下降
- Introduction to C language pointer
- js基础练习题
- Three waiting methods of selenium and three processing methods of alert pop-up
- Qsort - the sorting function in C language (with void*, callback function knowledge points
猜你喜欢

Day3 ---Flask 状态保持,异常处理与请求钩子

Source code of document type full-text retrieval knowledge base management system

李宏毅机器学习组队学习打卡活动day02---回归

Graph cuts learning

Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)

初识C语言——初识指针

初识C语言——常见的数据类型

Hi3516dv300 environment setup

p7 day1 初识Flask框架

The receiver sets the concurrency and current limit
随机推荐
How to quickly and effectively solve the problem of database connection failure
Seckill system design
项目登录注册思路
Flask登录实现
李宏毅机器学习组队学习打卡活动day01---机器学习介绍
C语言进制转换以及原补反码位运算介绍
上传七牛云的方法
Xiaomi mall project_ register
Redis publish subscribe mode
流程控制-分支
初识C语言——字符串+转义字符+注释
SQL database → constraint → design → multi table query → transaction
c语言字符串函数上:strlen、strcpy、strcat
创建项目 实现登录注册,生成jwt,发送验证码
Simplify the mybits framework of JDBC
map结构
Program environment and preprocessing (Part 2): define, undef, command line compilation, conditional compilation, file inclusion (super full collation, recommended collection!!!
Redis persistence
Hi3516dv300 environment setup
js进阶知识—函数