# Outputting tabular data to the console

Page 1 of 1

## 2 Replies - 7707 Views - Last Post: 18 September 2009 - 05:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=126648&amp;s=2bf60ed19e836461b560b1016d880e12&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Charlie IronGleet

Reputation: 2
• Posts: 225
• Joined: 29-January 09

# Outputting tabular data to the console

Posted 18 September 2009 - 03:20 PM

Could someone please help me fix up the following code? The code logically runs fine -- outputs decimal, hex, octal, binary equivalents for 1-256 -- the problem is that I can't figure out how to get the data to appear in nice even orderly rows and columns --- everything appears skewed.

I'm sure you'll see what I mean right away..

```class DecimalConversion
{
static void Main(string[] args)
{
Console.WriteLine("Decimal  Binary   Octal	Hexdecimal");
for (int i = 1; i <= 256; i++)
{

string x = Convert.ToString(i, 2);
string y = Convert.ToString(i, 8);
string z = Convert.ToString(i, 16);

Console.WriteLine("{0}		 {1}		 {2}		 {3}", i, x, y, z);
}
}
}

```

Thanks alot for your help!
Irongleet

Is This A Good Question/Topic? 0

## Replies To: Outputting tabular data to the console

### #2 MentalFloss

• .

Reputation: 619
• Posts: 1,590
• Joined: 02-September 09

## Re: Outputting tabular data to the console

Posted 18 September 2009 - 03:31 PM

Format it in the writeline.

Something like this, but may require some tweeking:

```class DecimalConversion
{
static void Main(string[] args)
{
Console.WriteLine("Decimal  Binary   Octal	Hexdecimal");
for (int i = 1; i <= 256; i++)
{

string x = Convert.ToString(i, 2);
string y = Convert.ToString(i, 8);
string z = Convert.ToString(i, 16);

Console.WriteLine("{0,-10}{1,-10}{2,-10}{3,-10}", i, x, y, z);
}

}
}

```

Edit: Update code...

```class DecimalConversion
{
static void Main(string[] args)
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}", "Decimal", "Binary", "Octal", "Hexadecimal");
for (int i = 1; i <= 256; i++)
{

string x = Convert.ToString(i, 2);
string y = Convert.ToString(i, 8);
string z = Convert.ToString(i, 16);

Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}", i, x, y, z);
}

}
}

```

This post has been edited by MentalFloss: 18 September 2009 - 03:39 PM

• Saucy!

Reputation: 6259
• Posts: 24,028
• Joined: 23-August 08

## Re: Outputting tabular data to the console

Posted 18 September 2009 - 05:44 PM

My saved links on .NET formatting:
http://blog.stevex.n...ting-in-csharp/
and
http://blogs.msdn.co.../29/564426.aspx