using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BPASmartClient.KLMCoffee.Protocal
{
public class BitValue
{
#region Byte位数据获取
///
/// 7 6 5 4 3 2 1 0
///
///
///
///
public bool GetBitValue(byte value,byte bit)
{
return (value & (byte)Math.Pow(2,bit)) > 0 ? true : false;
}
///
/// 设置某一位的值
///
///
/// 要设置的位, 值从低到高为 1-8
/// 要设置的值 true / false
///
public byte SetBitValue(byte data,int index,bool flag)
{
if (!((index > 8 || index < 1)))
{
int v = index < 2 ? index : (2 << (index - 2));
return flag ? (byte)(data | v) : (byte)(data & ~v);
}
else
return data;
}
#endregion
}
}