当前位置:网站首页>c# 用移位 >> 和运算与 &判断两个 二进制数 是否发生过改变
c# 用移位 >> 和运算与 &判断两个 二进制数 是否发生过改变
2022-07-26 14:13:00 【吴梓穆】
首先我们明确一点 二进制和十进制 十六进制只是给人看的, 电脑里都是二进制,代码里对int 进制 移位和运算与 都是操作的二进制数
代码如下
返回的结果是 十进制的 0 1 2 3 4…代表第几位(从右往左)发生了改变
private List<int> GetNewData(uint oldData, uint newData)
{
if (oldData == newData) return null;
List<int> result = new List<int>();
for (int i = 0; i < 24; i++)
{
uint v = (oldData >> i); //移位操作,左移1位相当于乘2 右移1位相当于除2 对于二进制的意义在于将数整体左移右移,超出的部分会被丢弃
//其实对于这里来说,因为和1按位与,结果只看最后一位是否都是1,结果要么0 要么是1,右移是为了把高位放到低位上,所以如果发生了变化,对应的位新旧值肯定不同
v = v & 0x00000001; //按位与, 两个整数按二进制,两位都是1时结果是1, 如1和3 二进制是 001 011, 1&3 = 001 结果是·1
uint v2 = (newData >> i);
v2 = v2 & 0x00000001;
if (v != v2)
{
result.Add((byte)i); //这里直接用i和转为byte是一样的
// result.Add(i);
}
}
return result;
}
边栏推荐
- uni-app从创建到运行到微信开发者工具
- Digital collections accelerate the breaking of the circle and help the industry find new opportunities
- 大小端模式
- UDP多线程在线聊天
- TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
- Iscc2021 lock problem solution
- 我的创作纪念日-从心出发
- GOM登录器配置免费版生成图文教程
- Meeting seating and submission for approval of OA project
- IDEA(warning)No artifacts configured
猜你喜欢

OpenCV中图像算术操作与逻辑操作

win10安装Dexdump并脱壳

Construction practice of pipeline engine of engineering efficiency ci/cd

Mlx90640 infrared thermal imager temperature sensor module development notes (6)

Uni app from creation to operation to wechat developer tool

聚力打造四个“高地”,携手合作伙伴共铸国云!

What is the problem of the time series database that has been developed for 5 years?

Basic syntax of MySQL DDL and DML and DQL

基于机器学习的技术术语识别研究综述

Plato farm is expected to further expand its ecosystem through elephant swap
随机推荐
Use cpolar to build a commercial website (apply for website security certificate)
android安全基础知识学习
[GYCTF2020]FlaskApp
Mysql-04 storage engine and data type
『SignalR』. Net using signalr for real-time communication
UDP多线程在线聊天
Circular queue (implemented in C language)
Research on technology subject division method based on patent multi-attribute fusion
如何做 APP 升级测试 ?
Focus on building four "highlands" and join hands with partners to build the national cloud!
Install dexdump on win10 and remove the shell
『BaGet』带你一分钟搭建自己的私有NuGet服务器
Research on Chinese medicine assisted diagnosis and treatment scheme integrating multiple natural language processing tasks -- taking diabetes as an example
C语言_结构体指针变量引入
What is restful style and its four specific implementation forms
[noip2003 popularity group] stack
Multithreading - thread pool
URL的使用下载资源
C language_ Structure pointer to access structure array
什么是Restful风格以及它的四种具体实现形式