Convierte un número decimal a cualquier base (octal, hexadecimal, binario etc) c# .NET

//Convierte un número decimal a cualquier base

//El metodo recibe un numero entewro y lo convierte a la base indicada.

        public string DecimalToBase(int intDec, int intNumBase)

        {

            string strBin = "";

            int[] resultado = new int[32];

            int MaxBit = 32;

            for (; intDec > 0; intDec /= intNumBase)

            {

                int rem = intDec % intNumBase;

                resultado[–MaxBit] = rem;

            }

            for (int i = 0; i < resultado.Length; i++)

                if ((int)resultado.GetValue(i) >= base10)

                    strBin += cHexa[(int)resultado.GetValue(i) % base10];

                else

                    strBin += resultado.GetValue(i);

            strBin = strBin.TrimStart(new char[] { ‘0’ });

            return strBin;

        }

About omaracostacasas

ING SOFTWARE
This entry was posted in Microsoft .NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s