终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace BPASmartClient.KLMCoffee.Protocal
  7. {
  8. public class BitValue
  9. {
  10. #region Byte位数据获取
  11. /// <summary>
  12. /// 7 6 5 4 3 2 1 0
  13. /// </summary>
  14. /// <param name="value"></param>
  15. /// <param name="bit"></param>
  16. /// <returns></returns>
  17. public bool GetBitValue(byte value,byte bit)
  18. {
  19. return (value & (byte)Math.Pow(2,bit)) > 0 ? true : false;
  20. }
  21. /// <summary>
  22. /// 设置某一位的值
  23. /// </summary>
  24. /// <param name="data"></param>
  25. /// <param name="index">要设置的位, 值从低到高为 1-8</param>
  26. /// <param name="flag">要设置的值 true / false</param>
  27. /// <returns></returns>
  28. public byte SetBitValue(byte data,int index,bool flag)
  29. {
  30. if (!((index > 8 || index < 1)))
  31. {
  32. int v = index < 2 ? index : (2 << (index - 2));
  33. return flag ? (byte)(data | v) : (byte)(data & ~v);
  34. }
  35. else
  36. return data;
  37. }
  38. #endregion
  39. }
  40. }