This code for binary to decimal. I didint see like this easy code. The other calculating codes are too long and complex. I made this and you can use easily.
M
mehmetali_06
@mehmetali_06
Posts
-
c# binary to decimal code -new- -
c# binary to decimal code -new-private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
string sayii = textBox1.Text.Substring(0, textBox1.Text.Length);
uint[] sayicc = new uint[textBox1.Text.Length];for (int i = 0; i < textBox1.Text.Length; i++) { sayicc\[i\] = Convert.ToUInt32(sayii\[i\] - 48); } uint\[\] dizi2 = new uint\[textBox1.Text.Length\]; uint bit = 1; for (int j = 0; j < textBox1.Text.Length; j++) { dizi2\[j\] = bit; bit \*= 2; } Array.Reverse(dizi2); uint deger = 0; for (int i = 0; i <= dizi2.Length - 1; i++) { dizi2\[i\] \*= sayicc\[i\]; if (sayicc\[i\] == 1) { deger += dizi2\[i\]; } } textBox2.Text = " " + deger.ToString(); } else { MessageBox.Show("Deger girilecek alan boş.", "HATA!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }