Hi, maybe this is what you want:
...
int remainder;
string result = string.Empty;
while (decimalNumber > 0)
{
remainder = decimalNumber % 2;
decimalNumber /= 2;
result = remainder.ToString() + result;
}
MessageBox.Show("Conversion was sucessful. Your binary code is: " + result, "Conversion Sucessful");
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Filter = "txt file|*.txt";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dlg.FileName))
{
sw.Write(result);
}
}
}
Or you can use File.WriteAllText:
...
int remainder;
string result = string.Empty;
while (decimalNumber > 0)
{
remainder = decimalNumber % 2;
decimalNumber /= 2;
result = remainder.ToString() + result;
}
MessageBox.Show("Conversion was sucessful. Your binary code is: " + result, "Conversion Sucessful");
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Filter = "txt file|*.txt";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
System.IO.File.WriteAllText(dlg.FileName, result);
}
}
No comments:
Post a Comment