File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 5
5
6
6
public class HexToOct
7
7
{
8
- //Function that takes the Hexadecimal number as input and returns the decimal form.
8
+ /*Function that takes the Hexadecimal number as input and returns the decimal form.
9
+ The input is recieved as a string and the return type is int*/
9
10
public static int hex2decimal (String s )
10
11
{
11
- String str = "0123456789ABCDEF" ;
12
+ String str = "0123456789ABCDEF" ;
12
13
s = s .toUpperCase ();
13
14
int val = 0 ;
14
15
for (int i = 0 ; i < s .length (); i ++)
@@ -19,20 +20,20 @@ public static int hex2decimal(String s)
19
20
}
20
21
return val ;
21
22
}
22
- // Main function that gets the hex input from user and converts it into octal.
23
+ // Main method that gets the hex input from user and converts it into octal.
23
24
public static void main (String args [])
24
25
{
25
26
String hexadecnum ;
26
27
int decnum , i =1 , j ;
27
- int octnum [] = new int [100 ];
28
+ int octnum [] = new int [100 ]; //Array to store the octal from of the hex number.
28
29
Scanner scan = new Scanner (System .in );
29
30
30
31
System .out .print ("Enter Hexadecimal Number : " );
31
- hexadecnum = scan .nextLine ();
32
+ hexadecnum = scan .nextLine ();
32
33
33
34
// first convert hexadecimal to decimal
34
35
35
- decnum = hex2decimal (hexadecnum );
36
+ decnum = hex2decimal (hexadecnum ); //Pass the string to the hex2decimal function and get the decimal form in variable decnum
36
37
37
38
// convert decimal to octal
38
39
You can’t perform that action at this time.
0 commit comments