Exemple #1
0
        public static (uint value, uint mask) ParseWithMask(string value)
        {
            value = value.Replace("_", "").Replace(",", "").Trim();
            value = value.Replace("0b", "");

            var dst = value
                      .Replace(".", "0")
                      .Replace("x", "0");
            var mask = value
                       .Replace("0", "1")
                       .Replace("1", "0")
                       .Replace(".", "1")
                       .Replace("x", "1");

            return(Convert.ToUInt32(dst, 2), Convert.ToUInt32(mask, 2));
        }
Exemple #2
0
        public static (UInt32 value, int bitNum) Parse(string value)
        {
            uint dst    = 0;
            int  bitNum = 0;

            value = value
                    .Replace("_", "")
                    .Replace(",", "")
                    .Trim();

            if (value.StartsWith("0x"))
            {
                //16進数
                dst    = Convert.ToUInt32(value, 16);
                bitNum = (value.Length - 2) * 8;
            }
            else if (value.StartsWith("0b"))
            {
                //2進数
                dst    = Convert.ToUInt32(value.Replace("0b", ""), 2);
                bitNum = (value.Length - 2);
            }
            else
            {
                //10進数
                dst    = Convert.ToUInt32(value, 10);
                bitNum = (int)Math.Log(Math.Pow(10, value.Length) - 1, 2);
            }

            return(dst, bitNum);
        }