Esempio n. 1
0
        /// <summary>
        /// 將點位轉換成 byte 值。
        /// </summary>
        /// <param name="posNumbers">點位</param>
        /// <returns></returns>
        public static byte PositionNumbersToByte(params int[] posNumbers)
        {
            BitArray bits = new BitArray(8, false);

            foreach (int posNum in posNumbers)
            {
                if (posNum < 1 || posNum > 6)
                {
                    throw new ArgumentException("參數錯誤:{posNum}。點位必須為 1~6 點!");
                }
                bits[posNum - 1] = true;
            }

            return(ConvertHelper.BitsToByte(bits));
        }
Esempio n. 2
0
        /// <summary>
        /// 將點位轉換成 byte 值。
        /// </summary>
        /// <param name="dots">點位</param>
        /// <returns></returns>
        public static byte DotsToByte(params int[] dots)
        {
            BitArray bits = new BitArray(8, false);

            foreach (int dotNum in dots)
            {
                if (dotNum < 1 || dotNum > 6)
                {
                    throw new ArgumentException("參數錯誤:點位必須為 1~6 點!");
                }
                bits[dotNum - 1] = true;
            }

            return(ConvertHelper.BitsToByte(bits));
        }
Esempio n. 3
0
        /// <summary>
        /// 將點位轉換成 byte 值。
        /// </summary>
        /// <param name="posNumbers">點位</param>
        /// <returns></returns>
        public static byte PositionNumberStringToByte(string posNumberString)
        {
            BitArray bits = new BitArray(8, false);

            for (int i = 0; i < posNumberString.Length; i++)
            {
                int posNum = StrHelper.ToInteger(posNumberString[i].ToString(), 0);
                if (posNum < 1 || posNum > 6)
                {
                    throw new ArgumentException($"參數錯誤:'{posNumberString}'。點位必須為 1~6 點!");
                }
                bits[posNum - 1] = true;
            }

            return(ConvertHelper.BitsToByte(bits));
        }