Convert Decimal Number to Hexadecimal Number in Windows Store App


In this article I explain how to convert a number using decimal to a number using hexadecimal in Windows Store App. So here I will describe both decimal and hexadecimal numbers and some character values of Unicode.

Decimal Number: A number expressed using a base 10 numbering system using digits from 0 to 9.

Hexadecimal Number : A number expressed using a base 16 numbering system using digits from 0 to 9 and A to F.

Where A=10, B=11, C=12, D=13, E=14 and F=15.

Conversion Example: suppose you want to convert number expressed as decimal 500 to hexadecimal. Then use the following procedure:

Step 1 :500/16  Then Remainder=4 , Quotient=31
Step 2 : 31/16   Then Remainder=15  , Quotient=1
Step 3 : 1/16  Then  Remainder=1 , Quotient =0

Hence the equivalent in hexadecimal = 4F1. Because F=15.

Now understand some character values of Unicode that are needed to understand this conversion.

Unicode Value of Character 0=48
Unicode Value of Character 1=49
Unicode Value of Character 2=50
Unicode Value of Character 3=51
Unicode Value of Character 4=52
Unicode Value of Character 5=53
Unicode Value of Character 6=54

Unicode Value of Character 7=55
Unicode Value of Character 8=56
Unicode Value of Character 9=57 and

Unicode Value of Character A=65
Unicode Value of Character B=66

Unicode Value of Character C=67

Unicode Value of Character D=68
Unicode Value of Character E=69

Unicode Value of Character F=70

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):










    <Grid Background="red">


            <ColumnDefinition Width="313*"/>

            <ColumnDefinition Width="254*"/>

            <ColumnDefinition Width="788*"/>



            <RowDefinition Height="78*"/>

            <RowDefinition Height="49*"/>

            <RowDefinition Height="37*"/>

            <RowDefinition Height="40*"/>

            <RowDefinition Height="39*"/>

            <RowDefinition Height="525*"/>


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

        <TextBlock Text="Enter Decimal 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 hexadecimal 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"></Button>



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;

using Windows.UI.Xaml.Navigation;


namespace binding_app


    public sealed partial class MainPage : Page


        public MainPage()




        protected override void OnNavigatedTo(NavigationEventArgs e)



        private void button1_Click(object sender, RoutedEventArgs e)


            long decnum = 0;

            int[] hexnum = new int[20];

            int i = 0, r;

            decnum = long.Parse(textbox1.Text);

            while (decnum != 0)


                r =(int) decnum % 16;

                if (r < 10)


                    r = r + 48;




                    r = r + 55;


                hexnum[i++] = r;

                decnum = decnum / 16;


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


                text1.Text +=(char) hexnum[j];






Step 4

Now run your app.


Similar Articles