当前位置:网站首页>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 .
边栏推荐
- Lua tvalue structure
- TestEngine with ID ‘junit-vintage‘ failed to discover tests
- 程序分析与优化 - 6 循环优化
- Knowledge of wireless card driver
- Mémoire de l'examen d'entrée à l'université
- 【mysql进阶】索引分类及索引优化方案(五)
- Binary tree traversal
- Program analysis and Optimization - 6 loop optimization
- Programmer interview golden classic good question / interview question 01.05 Edit once
- Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform
猜你喜欢

如果要打造品牌知名度,可以选择什么出价策略?

Is Shell Scripting really a big technology?

高考回忆录

Alicloud development board vscode development environment setup

浅谈中国程序员为什么要跳槽?

CSDN blog points rule

Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform

Dynamic search advertising intelligent search for matching keywords

Design of PLC intelligent slave station based on PROFIBUS DP protocol

TestEngine with ID ‘junit-vintage‘ failed to discover tests
随机推荐
2000. reverse word prefix
After reading the question, you will point to offer 16 Integer power of numeric value
Shell脚本到底是什么高大上的技术吗?
基于Profibus-DP协议的PLC智能从站设计
TestEngine with ID ‘junit-vintage‘ failed to discover tests
Leetcode 2185. 统计包含给定前缀的字符串
Use of pytorch (to be supplemented)
Player actual combat 14 display YUV
atomic and exclusive operation
Brush one question every day /537 Complex multiplication
Player practice 19 xaudio turn on audio
高考回忆录
NotePad 常用设置
Relevant knowledge points of cocoapods
SystemC uses SC_ report_ Handler processing log printing
Chapter IV expression
SystemC:SC_ Thread and SC_ METHOD
English learning plan
Alibaba cloud development board haas510 parses serial port JSON data and sends attributes
Player actual combat 16 xdecode class