您现在的位置是:首页 > 编程 > 数据结构和算法数据结构和算法
关于 int 和 long 位运算问题
Tdou2022-04-13【数据结构和算法】人已围观
简介在位运算 由于数字是int 型 在做移位时 int 会溢出
解决方案就是在位运算 移位的时候 1<<n 改为 1L<<n
https://github.com/tdouguo/BitsOperation
https://www.jianshu.com/p/ed50be6ad1e2
https://blog.csdn.ne
https://github.com/tdouguo/BitsOperation
在位运算 由于数字是int 型 在做移位时 int 会溢出
解决方案就是在位运算 移位的时候 1<<n 改为 1L<<n
打赏
在位运算 由于数字是int 型 在做移位时 int 会溢出
解决方案就是在位运算 移位的时候 1<<n 改为 1L<<n
/// <summary> /// 位运算 最大8x8 /// </summary> public partial class BitItem { public BitItem() { mark = 0; } private long mark; public long Mark { get { return mark; } } public void Choose(int index) { mark |= (1L << index); } public void UnChoose(int index) { mark &= ~(1L << index); } public bool IsChoose(int index) { long isHave = mark & (1L << index); return isHave != 0; } }
- https://www.jianshu.com/p/ed50be6ad1e2
- https://blog.csdn.net/yu121380/article/details/81041476
Tags:Unity技术点
很赞哦! ()
微信收款码
支付宝收款码