using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
namespace Sog
{
public static class BitUtils
{
///
/// value的某一位是否是1
///
///
/// 从1开始,1-32
///
public static bool IsBitSet(uint value, int bit)
{
uint bitValue = ((uint)1) << (bit - 1);
return (value & bitValue) > 0;
}
///
/// value的某一位是否是1
///
///
/// 从1开始,1-32
///
public static bool IsBitSet(ulong value, int bit)
{
ulong bitValue = ((ulong)1) << (bit - 1);
if ((value & bitValue) > 0)
{
return true;
}
return false;
}
public static uint BitSet(uint value, int bit)
{
uint bitValue = ((uint)1) << (bit - 1);
value |= bitValue;
return value;
}
public static ulong BitSet(ulong value, int bit)
{
ulong bitValue = ((ulong)1) << (bit - 1);
value |= bitValue;
return value;
}
public static uint BitClear(uint value, int bit)
{
uint bitValue = ((uint)1) << (bit - 1);
value &= (~bitValue);
return value;
}
public static ulong BitClear(ulong value, int bit)
{
ulong bitValue = ((ulong)1) << (bit - 1);
value &= (~bitValue);
return value;
}
}
}