终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

43 líneas
1.2 KiB

  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. }