# Octal to Binary Conversion in Windows Store App

In this article I explain how to convert octal to binary number system in Windows Store App.

In this article I am going to describe how to convert octal based number into a binary based number. So first of all I will describe what an octal based number is and what a binary based number is.

Octal Number: A number expressed using the base 8 number system with digits 0 to 7.

Binary Number: A number expressed using the base 2 number with digits 0 and 1.

Use the following procedure to create it.

Step 1

First of all you must create a new Windows Store Application.

Open Visual Studio 2012
"File" -> "New" -> "Project..."
Choose "Template" -> "Visual C#" -> "Window Store app"
Choose "Blank App (XAML)" then rename the application

Step 2

Write the following XAML code in "Mainpage.Xaml" (that is available in Solution Explorer):

<Page

x:Class="octal_to_binary_app.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="using:octal_to_binary_app"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d">

<Grid Background="red">

<Grid.ColumnDefinitions>

<ColumnDefinition Width="316*"/>

<ColumnDefinition Width="256*"/>

<ColumnDefinition Width="295*"/>

<ColumnDefinition Width="499*"/>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height="78*"/>

<RowDefinition Height="49*"/>

<RowDefinition Height="37*"/>

<RowDefinition Height="40*"/>

<RowDefinition Height="39*"/>

<RowDefinition Height="525*"/>

</Grid.RowDefinitions>

<TextBlock Text="Octal to binary Converter app" Grid.ColumnSpan="4" Grid.Row="1" Foreground="White" FontSize="20" FontFamily="Arial" TextAlignment="Center" FontWeight="ExtraBold"></TextBlock>

<TextBlock Text="Entern Octal Number :" FontFamily="Arial" FontSize="15" Foreground="White" Grid.Column="1" Grid.Row="2" Grid.RowSpan="4" FontWeight="ExtraBold"></TextBlock>

<TextBox x:Name="textbox1" Grid.Column="2" Grid.Row="2" Width="200" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" />

<TextBlock Text="Eqivalent binary Number is " FontSize="15" Foreground="White" Grid.Column="1" Grid.Row="3" FontWeight="ExtraBold"></TextBlock>

<TextBlock x:Name="text1" FontSize="15" Foreground="White" Grid.Column="2" Grid.Row="3" Width="200" HorizontalAlignment="Left" ></TextBlock>

<Button x:Name="button1" Grid.Column="2" Grid.Row="4" Background="Yellow" Foreground="Black" Width="150" Content="Click" Click="button1_Click" Margin="0,1,0,0"></Button>

<TextBlock x:Name="error" FontSize="15" Foreground="White" Grid.Column="3" Grid.Row="3" Width="200" HorizontalAlignment="Left"></TextBlock>

</Grid>

</Page>

Step 3

Now write the following C# code for the button within "Mainpage.Xaml.cs".

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

namespace octal_to_binary_app

{

public sealed partial class MainPage : Page

{

public MainPage()

{

this.InitializeComponent();

}

{

}

private void button1_Click(object sender, RoutedEventArgs e)

{

string[] octalnum = new string[25];

int r,i=0;

int num = Convert.ToInt32(textbox1.Text);

while (num != 0)

{

r = num % 10;

switch (r)

{

case 0:

octalnum[i++]="000";

break;

case 1:

octalnum[i++]="001";

break;

case 2:

octalnum[i++]="010";

break;

case 3:

octalnum[i++]="011";

break;

case 4:

octalnum[i++]="100";

break;

case 5:

octalnum[i++]="101";

break;

case 6:

octalnum[i++]="110";;

break;

case 7:

octalnum[i++]="111";

break;

default:

{

error.Text = "Invalid octal number";

textbox1.Text = "";

goto ax;

}

}

num = num / 10;

}

for (int j = i-1; j >=0; j--)

{

text1.Text+= octalnum[j];

}

ax: { }

}

}

}

Step 4