当前位置:网站首页>How to set, reset and reverse bit
How to set, reset and reverse bit
2022-06-12 14:13:00 【Panda general】
Set operation
Use bit operations OR(|) Operator to set a bit Position as 1.
number |= 1UL << n;
take number Of the n Location 1,n from 0 Start .
If number exceed unsigned long length , Then use 1ULL << n.
Reset operation
Use bit operations AND(&) Operator to set a bit Position as 0.
number &= ~(1UL << n);
take number Of the n Location 0,n from 0 Start .
Reverse operation
Use bit operations XOR(^) Operator to set a bit Bit inversion .
number ^= 1UL << n;
take number Of the n Bit inversion .
The retrieval
take number Move right n position , And then use AND Operator match .
bit = (number >> n)& 1U;
This will get number The first n The value of the bit is stored in bit in .
边栏推荐
- [semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX
- 阿里云开发板HaaS510连接物联网平台--HaaS征文
- [advanced MySQL] evolution of MySQL index data structure (IV)
- Dynamic search advertising intelligent search for matching keywords
- Démontage et modification de la machine publicitaire - décompression amateur
- NotePad 常用设置
- My resume.
- Llvm 13.1 new pass plug-in form [for win]
- Create a slice slice pit using the make method
- Alicloud development board vscode development environment setup
猜你喜欢

Démontage et modification de la machine publicitaire - décompression amateur

Relevant knowledge points of cocoapods

Create a small root heap and judge the node relationship (also.C\u str() substr(),atoi(),string. Use of find())

完美收官|详解 Go 分布式链路追踪实现原理

Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode

Axi4 increase burst / wrap burst/ fix burst and narrow transfer

Crack WinRAR to ad pop-up window

WinDbg preview debug analysis createtoolhelp32snapshot
![[video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day](/img/8d/3bfb5d2798797be3e0b10e25c978d3.png)
[video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day

Alicloud development board vscode development environment setup
随机推荐
Dial up and Ethernet
Factory mode of "object creation" mode
Knowledge of wireless card driver
Player practice 20 unpacking thread
单总线温度传感器18B20数据上云(阿里云)
Brush one question every day /537 Complex multiplication
Create a small root heap and judge the node relationship (also.C\u str() substr(),atoi(),string. Use of find())
Cmake basic tutorial - 02 b-hello-cmake
基于Profibus-DP协议的PLC智能从站设计
Leetcode 2176. Count equal and divisible pairs in an array
If you want to build brand awareness, what bidding strategy can you choose?
Leetcode questions brushing February /1020 Number of enclaves
阿里云开发板HaaS510连接物联网平台--HaaS征文
The original Xiaoyuan personal blog project that has been around for a month is open source (the blog has basic functions, including background management)
阿里云开发板HaaS510响应UART串口指令
Cmake basic tutorial - 01 a-hello-cmake
Redis core configuration and advanced data types
How to brush leetcode
Reverse analysis from x86 to x64tips
阿里云开发板vscode开发环境搭建