Last active
August 29, 2015 14:23
-
-
Save vdonchev/162078d136dfe0cbe9c9 to your computer and use it in GitHub Desktop.
DecToHex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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