File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ void main (void )
6
+ {
7
+ int valueToConvert = 0 ; // Holds user input
8
+ int hexArray[8 ]; // Contains hex values backwards
9
+ int i = 0 ; // counter
10
+ int lValue = 0 ; // Last Value of Hex result
11
+
12
+ cout << " Enter a Decimal Value" << endl; // Displays request to stdout
13
+ cin >> valueToConvert; // Stores value into valueToConvert via user input
14
+
15
+ while (valueToConvert > 0 ) // Dec to Hex Algorithm
16
+ {
17
+ lValue = valueToConvert % 16 ; // Gets remainder
18
+ valueToConvert = valueToConvert / 16 ;
19
+ hexArray[i] = lValue; // Stores converted values into an array
20
+ i++;
21
+ }
22
+ cout << " Hex Value: " ;
23
+ while (i > 0 )
24
+ {
25
+ // Displays Hex Letters to stdout
26
+ switch (hexArray[i - 1 ]) {
27
+ case 10 :
28
+ cout << " A" ;
29
+ break ;
30
+ case 11 :
31
+ cout << " B" ;
32
+ break ;
33
+ case 12 :
34
+ cout << " C" ;
35
+ break ;
36
+ case 13 :
37
+ cout << " D" ;
38
+ break ;
39
+ case 14 :
40
+ cout << " E" ;
41
+ break ;
42
+ case 15 :
43
+ cout << " F" ;
44
+ break ;
45
+ default :
46
+ cout << hexArray[i - 1 ]; // if not an int 10 - 15, displays int value
47
+ }
48
+ i--;
49
+ }
50
+ cout << endl;
51
+ }
You can’t perform that action at this time.
0 commit comments