C Sharp'ta 2'lik sayıyı 10luk tabanda yazılışı

0
Onaylı Üye
Üye
Katılım
6 Nisan 2010
Mesajlar
2,892
Tepki puanı
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2_lik_sistem
{
class Program
{
static void Main(string[] args)
{
double us, c, toplam = 0;
int boy, sayi;
string s;
char a;
Console.Write("2'lik sistemde bir sayı giriniz=");
s = Console.ReadLine();
boy = s.Length;
Console.Write("Girilen sayının uzunluğu={0}", boy);
for (int i = 0; i < boy; i++)
{
a = s;
sayi = Convert.ToInt16(a);
sayi = sayi - 48;
us = Math.Pow(2, boy - (i + 1));
c = sayi * us;
toplam = toplam + c;
Console.WriteLine(sayi + "x" + us + "=" + c);
}
Console.Write("Sayiların 10'luk tabanda karşılığı={0}", toplam + "n");
Console.ReadLine();
}
}
}
kaynak
 
Geri
Üst