-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex43.cs
120 lines (111 loc) · 3.45 KB
/
Ex43.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace day1
{
class Ex43
{
static void convertSingle(int decNum)
{
int number = decNum;
string hexdec = "";
string original_hexdec = "";
int q = number;
int r = 0;
while (q >0)
{
r = q % 16;
q = q / 16;
if (r > 9)
{
switch (r)
{
case 10:
r = 65;
break;
case 11:
r = 66;
break;
case 12:
r = 67;
break;
case 13:
r = 68;
break;
case 14:
r = 69;
break;
case 15:
r = 70;
break;
}
hexdec = hexdec +(char)r;
}
else
{
hexdec = hexdec + r;
}
}
for (int i = hexdec.Length-1; i >= 0; i--)
{
original_hexdec = original_hexdec + hexdec.ElementAt(i);
}
Console.WriteLine("hexdec=" + original_hexdec);
}
static void Main(string[] args)
{
// convertSingle(317547);
convertDecToHex();
}
static void convertDecToHex()
{
for (int i = 1; i <= 100; i++)
{
string hexdec = "";
string original_hexdec = "";
int q = i;
int r = 0;
while (q > 0)
{
r = q % 16;
q = q / 16;
if (r > 9)
{
switch (r)
{
case 10:
r = 65;
break;
case 11:
r = 66;
break;
case 12:
r = 67;
break;
case 13:
r = 68;
break;
case 14:
r = 69;
break;
case 15:
r = 70;
break;
}
hexdec = hexdec + (char)r;
}
else
{
hexdec = hexdec + r;
}
}
for (int j = hexdec.Length - 1; j >= 0; j--)
{
original_hexdec = original_hexdec + hexdec.ElementAt(j);
}
System.Console.WriteLine("The hex dec value of {0} is {1}", i, original_hexdec);
}
}
}
}