Harren
public text v1 · immutable
//KONVERTERA TILL BINÄRTAL
//Hämtar ett tal att konvertera från textrutan
double.TryParse(textBox1.Text, out conv);
double tempDec = 0;
int t = 0;
for (int i = 0; tempDec < conv; i++)
{
tempDec = Math.Pow(2, i);
t = i;
}
double tempDec2 = conv;
string bin = "";
for (int i = t; i >= 0; i--)
{
if (Math.Pow(2, i) <= tempDec2)
{
tempDec2 = tempDec2 - Math.Pow(2, i);
bin += "1";
}
else
{
bin += "0";
}
}
// skriver ut binärtalet i textrutan
textBox1.Text = bin;