Format integer as octal and binary numbers : int format « Data Types « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Data Types » int formatScreenshots 
Format integer as octal and binary numbers
   

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {

      int[] numbers = -111111122222222 };
      Console.WriteLine("{0,8}   {1,32}   {2,11}   {3,10}""Value""Binary""Octal""Hex");
      foreach (int number in numbers) {
         Console.WriteLine("{0,8}   {1,32}   {2,11}   {3,10}"
                           number, Convert.ToString(number, 2)
                           Convert.ToString(number, 8)
                           Convert.ToString(number, 16));
      }      
   }
}
/*

   Value                             Binary         Octal          Hex
      -1   11111111111111111111111111111111   37777777777     ffffffff
  111111                  11011001000000111        331007        1b207
22222222          1010100110001010110001110     124612616      153158e


*/

   
    
    
  
Related examples in the same category
1.Format integer: C
2.Format integer with default formatting
3.Format integer with 3 digits and leading zeros
4.Format integer with 1 decimal digit
5.Format integer as hexadecimal
6.Format integer with eight hexadecimal digits
7.Use standard numeric format specifier: C
8.Use standard numeric format specifier: D8
9.Use standard numeric format specifier: E4
10.Use standard numeric format specifier: e3
11.Use standard numeric format specifier: F
12.Use standard numeric format specifier: N
13.Use standard numeric format specifier: P
14.Use standard numeric format specifier: X
15.Use standard numeric format specifier: 0,0.000
16.Use standard numeric format specifier: #,#.00#;(#,#.00#)
17.Int32.ToString (IFormatProvider)
18.Int32.ToString Method (String)
19.Int32.ToString Method (String, IFormatProvider)
20.Int32.ToString Converts the numeric value of this instance to its equivalent string representation.
21.double value format vs int value format
22.Add Ordinal Suffix
23.Converts an integer into a roman numeral.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.