36进制转换10进制

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        Dictionary<string, int> dic = new Dictionary<string, int> { };
        string str_input = "";
        
        public Form1()
        {
            InitializeComponent();    
            string str_key = "";
            int value = 0;

            for (int i = 55; i <= 90; i++)
            {
                str_key = i < 65 ? value.ToString() : ((char)i).ToString();
                dic.Add(str_key, value);
                value += 1;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int i_ten = 0;
            str_input = textBox1.Text.ToUpper();
            int len = str_input.Length;
            if (len == 1)
            {
                i_ten = dic[str_input];
            }
            else
            {
                for (int i = 1; i <= len; i++)
                {
                    if (i == len)
                    {
                        i_ten += dic[str_input.Substring(i - 1, 1)];
                    }
                    else
                    {
                        i_ten += dic[str_input.Substring(i - 1, 1)] * int.Parse(Math.Pow(36, len - i).ToString());
                    }

                }
            }
            textBox2.Text = str_input == "" ? "" :i_ten.ToString();
        }
    }
}

 

上一篇:正向最大匹配法


下一篇:2021年HW0day-奇安信 网康下一代防火墙 RCE漏洞细节