Exemplo n.º 1
0
        private void ConvertBus(EnumerationSystem _old, EnumerationSystem _new)
        {
            if (Text.Length == 0)
            {
                return;
            }

            int num = 0;

            switch (_old)
            {
            case EnumerationSystem.Bin:
                num = Convert.ToInt32(Text, 2);
                break;

            case EnumerationSystem.Dec:
                num = Convert.ToInt32(Text, 10);
                break;

            case EnumerationSystem.Hex:
                num = Convert.ToInt32(Text, 16);
                break;

            case EnumerationSystem.Oct:
                num = Convert.ToInt32(Text, 8);
                break;

            default:
                break;
            }

            switch (_new)
            {
            case EnumerationSystem.Bin:
                Text = Convert.ToString(num, 2);
                break;

            case EnumerationSystem.Dec:
                Text = Convert.ToString(num, 10);
                break;

            case EnumerationSystem.Hex:
                Text = Convert.ToString(num, 16);
                break;

            case EnumerationSystem.Oct:
                Text = Convert.ToString(num, 8);
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Распарсивание переменной Integer в VCD формате
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static VHDLIntegerValue ToInteger_VALUE(string text)
        {
            if (string.IsNullOrEmpty(text) == true)
            {
                throw new Exception("String is null or empty");
            }
            EnumerationSystem bus = EnumerationSystem.Bin;
            int bus_int           = 0;

            switch (text[0])
            {
            case 'b':
                bus     = EnumerationSystem.Bin;
                bus_int = 2;
                break;

            case 'o':
                bus     = EnumerationSystem.Oct;
                bus_int = 8;
                break;

            case 'd':
                bus     = EnumerationSystem.Dec;
                bus_int = 10;
                break;

            case 'h':
                bus     = EnumerationSystem.Hex;
                bus_int = 16;
                break;

            default:
                throw new Exception("Invalid enumeration system");
            }

            int pow = 1;
            int res = 0;

            for (int i = text.Length - 1; i >= 1; i--)
            {
                int num = CharToInt(text[i], bus);
                res += num * pow;
                pow *= bus_int;
            }
            return(new VHDLIntegerValue(res));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Перевод одного символа в число
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="bus"></param>
        /// <returns></returns>
        public static Int32 CharToInt(char symbol, EnumerationSystem bus)
        {
            Int32 res = 0;

            switch (symbol)
            {
            case '0':
                res = 0;
                break;

            case '1':
                res = 1;
                break;

            case '2':
                res = 2;
                break;

            case '3':
                res = 3;
                break;

            case '4':
                res = 4;
                break;

            case '5':
                res = 5;
                break;

            case '6':
                res = 6;
                break;

            case '7':
                res = 7;
                break;

            case '8':
                res = 8;
                break;

            case '9':
                res = 9;
                break;

            case 'A':
                res = 10;
                break;

            case 'B':
                res = 11;
                break;

            case 'C':
                res = 12;
                break;

            case 'D':
                res = 13;
                break;

            case 'E':
                res = 14;
                break;

            case 'F':
                res = 15;
                break;

            default:
                throw new Exception("Invalid character");
            }

            switch (bus)
            {
            case EnumerationSystem.Bin:
                if ((res == 0) || (res == 1))
                {
                    return(res);
                }
                break;

            case EnumerationSystem.Oct:
                if ((res >= 0) && (res <= 7))
                {
                    return(res);
                }
                break;

            case EnumerationSystem.Dec:
                if ((res >= 0) && (res <= 9))
                {
                    return(res);
                }
                break;

            case EnumerationSystem.Hex:
                if ((res >= 0) && (res <= 15))
                {
                    return(res);
                }
                break;
            }

            throw new Exception("Parsing failed");
        }