How to convert numbers between hexadecimal and decimal

前端 未结 17 1286
情歌与酒
情歌与酒 2020-11-22 05:30

How do you convert between hexadecimal numbers and decimal numbers in C#?

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 06:18

    This is not really easiest way but this source code enable you to right any types of octal number i.e 23.214, 23 and 0.512 and so on. Hope this will help you..

        public string octal_to_decimal(string m_value)
        {
            double i, j, x = 0;
            Int64 main_value;
            int k = 0;
            bool pw = true, ch;
            int position_pt = m_value.IndexOf(".");
            if (position_pt == -1)
            {
                main_value = Convert.ToInt64(m_value);
                ch = false;
            }
            else
            {
                main_value = Convert.ToInt64(m_value.Remove(position_pt, m_value.Length - position_pt));
                ch = true;
            }
    
            while (k <= 1)
            {
                do
                {
                    i = main_value % 10;                                        // Return Remainder
                    i = i * Convert.ToDouble(Math.Pow(8, x));                   // calculate power
                    if (pw)
                        x++;
                    else
                        x--;
                    o_to_d = o_to_d + i;                                        // Saving Required calculated value in main variable
                    main_value = main_value / 10;                               // Dividing the main value 
                }
                while (main_value >= 1);
                if (ch)
                {
                    k++;
                    main_value = Convert.ToInt64(Reversestring(m_value.Remove(0, position_pt + 1)));
                }
                else
                    k = 2;
                pw = false;
                x = -1;
            }
            return (Convert.ToString(o_to_d));
        }    
    

提交回复
热议问题