Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Last active August 29, 2015 14:23
Show Gist options
  • Save vdonchev/162078d136dfe0cbe9c9 to your computer and use it in GitHub Desktop.
Save vdonchev/162078d136dfe0cbe9c9 to your computer and use it in GitHub Desktop.
DecToHex
using System;
using System.Text;
class DecimalToHexadecimalNumber
{
static void Main()
{
Console.Write("Insert a Decimal number: ");
long dNum = long.Parse(Console.ReadLine());
StringBuilder hex = new StringBuilder();
while (dNum > 0)
{
long curNum = dNum % 16;
if (curNum >= 10)
{
hex.Insert(0, (char)(curNum + '7'));
}
else
{
hex.Insert(0, curNum);
}
dNum /= 16;
}
Console.WriteLine(hex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment