当前位置:网站首页>Day 8 of learning C language
Day 8 of learning C language
2022-07-27 09:17:00 【ruin987】
Binary
All files are ultimately binary
Text and binary
The advantage of text is that it is easy for people to read and write . And cross platform
The disadvantage of text is that the program input and output must be formatted , Spending big
The disadvantage of binary system is that it is difficult for human to read and write , And not cross platform
int The sizes of are inconsistent . The problem of big and small end ...
The advantage of binary is that the program reads and writes fast
Locate... In the file
long ftell(FILE*stream);
int fseek(FILE*stream,long offset,int whence);
SEEK_SET : Start from scratch
SEEK_CUR : From the current position
SEEK_END : Start at the end ( Come back )
Bitwise operation
C Bitwise operators of language :
| & | Bitwise AND |
| | | Bitwise OR |
| ~ | According to the not |
| ^ | Bitwise XOR |
| << | Move left |
| >> | Move right |
Bitwise AND &
If (x)i ==1 also (y)i ==1, that ( x & y)i = 1
Otherwise (x & y) i= 0
Bitwise and are commonly used in two applications :
Let one or more bits be 0: x & 0xFE
Take a paragraph from a number :x & 0xFF
Press bit or |
If (x)i == 1 or (y)i == 1, that (x | y)i = 1
Otherwise , (x | y)i == 0
Bitwise OR commonly used in two applications :
Make one or more persons 1: x | 0x01
Put the two numbers together : 0x00FF | 0xFF00
According to the not ~
(~x)i = 1 - (x)i
hold 1 A into 0,0 Displacement 1
Want to get all the bits as 1 Number of numbers : ~0
7 The binary of is 0111, x|7 Make low 3 Position as 1
x& ~7, It makes it low 3 Position as 0
Bitwise XOR ^
If (x)i ==(y)i, that (x^y)i = 0
Otherwise , (x ^ y)i == 1
If the two bits are equal , So the result is 0; It's not equal , The result is 1
If x and y equal , that x^y As the result of the 0
XOR a variable twice with the same value , It's like doing nothing
x ^ y ^ y---> x
Move left
i<<j
i All the bits in the move to the left j A place , And the right side is filled with 0
All less than int The type of , Shift to int The way to do it , The result is int
x<<=1 Equivalent to x *=2
x<<=n Equivalent to x *=2^n
Move right
i >> j
i All the positions in the move to the right j position
All less than int The type of , Shift to int The way to do it , The result is int
about unsigned The type of , Fill in on the left 0
about signed The type of , Fill in the original highest position on the left ( Leave the sign unchanged )
x>>=1 Equivalent to x /= 2
x>>=n Equivalent to x/=2^n
Logical operation and bitwise operation
For logical operations , He only sees two values : 0 and 1
It can be considered that logical operation is equivalent to all non 0 It's worth it 1, Then do bitwise operations
5 & 4 --->4 and 5&&4---->1&1---->1
5 | 4--->5 and 5 || 4---->1 | 1--->1
~4--->3 and !4--->!1---->0
Bit segment
Can be accessed directly with the member name of the bit field
Specific shift . And Or it's convenient
The compiler arranges the bits , Not portable
When the required bits exceed int Multiple... Will be used int
边栏推荐
- [C language - zero foundation lesson 10] adventure of array Kingdom
- Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
- NPM install error forced installation
- Pyqt5 rapid development and practice 4.1 qmainwindow
- Pymongo fuzzy query
- Five kinds of 3D attention/transformer finishing (a-scn, point attention, CAA, offset attention, point transformer)
- [C language - zero foundation _ study _ review _ lesson 4] data types and operations
- Antdesign a-modal user-defined instruction realizes dragging and zooming in and out
- 如何注册码云账号
- [cloud co creation] Huawei cloud: full stack technology innovation, deep digitalization, leading cloud native
猜你喜欢

Deep understanding of Kalman filter (1): background knowledge

async/await的执行顺序以及宏任务和微任务

基于restful页面数据交互

Pytorch custom CUDA operator tutorial and runtime analysis

一些实用、常用、效率越来越高的 Kubernetes 别名
![[interprocess communication IPC] - semaphore learning](/img/47/b76c329e748726097219abce28fce8.png)
[interprocess communication IPC] - semaphore learning

As a VC, the auction house invested Web3 for the first time

拍卖行做VC,第一次出手就投了个Web3

【微服务~Sentinel】Sentinel之dashboard控制面板
![[micro service ~sentinel] sentinel dashboard control panel](/img/df/2fbe7826ea2b80a81d29351052ae28.png)
[micro service ~sentinel] sentinel dashboard control panel
随机推荐
As a VC, the auction house invested Web3 for the first time
BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Trans
易语言编程: 让读屏软件可获取标签控件的文本
[C language _ study _ exam _ review lesson 3] overview of ASCII code and C language
< script> detailed explanation of label content
Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises
CUDA programming-01: build CUDA Programming Environment
ctfshow 终极考核
Storage and computing engine
The lifecycle of arkui development framework components
pollFirst(),pollLast(),peekFirst(),peekLast()
How to upload dynamic GIF map in blog
巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
Summary of traversal methods
The difference between computed and watch
HUAWEI 机试题:火星文计算 js
[interprocess communication IPC] - semaphore learning
npm和yarn 更新依赖包
[leetcode -- the second day of introduction to programming ability] operator (the number of bit 1 / the difference between the sum of the products of integers)