-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDecimal to HexaDecimal Conversion.cs
62 lines (58 loc) · 1.96 KB
/
Decimal to HexaDecimal Conversion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NumberConversion3
{
class Program
{
static void Main(string[] args)
{
int Decimal,n,remainder,i;
string HexaDecimal = string.Empty;
Console.WriteLine("Decimal to HexaDecimal Conversion");
Decimal = Convert.ToInt32(Console.ReadLine());
for (n = Decimal; n != 0; n = n / 16)
{
remainder = n % 16;
switch (remainder)
{
case 10:
string R = "A";
HexaDecimal = HexaDecimal +R;
break;
case 11:
string rem = "B";
HexaDecimal = HexaDecimal +rem;
break;
case 12:
string val = "C";
HexaDecimal = HexaDecimal + val;
break;
case 13:
string Rem = "D";
HexaDecimal = HexaDecimal + Rem;
break;
case 14:
string value = "E";
HexaDecimal = HexaDecimal + value;
break;
case 15:
string Remainder = "F";
HexaDecimal = HexaDecimal + Remainder;
break;
default:
HexaDecimal = HexaDecimal + remainder.ToString();
break;
}
}
Console.WriteLine("The HexaDecimal Converted Value is:");
for (i = HexaDecimal.Length - 1; i >= 0; i--)
{
Console.Write(HexaDecimal[i]);
}
Console.ReadLine();
}
}
}