File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 55
66public class HexToOct
77{
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*/
910 public static int hex2decimal (String s )
1011 {
11- String str = "0123456789ABCDEF" ;
12+ String str = "0123456789ABCDEF" ;
1213 s = s .toUpperCase ();
1314 int val = 0 ;
1415 for (int i = 0 ; i < s .length (); i ++)
@@ -19,20 +20,20 @@ public static int hex2decimal(String s)
1920 }
2021 return val ;
2122 }
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.
2324 public static void main (String args [])
2425 {
2526 String hexadecnum ;
2627 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.
2829 Scanner scan = new Scanner (System .in );
2930
3031 System .out .print ("Enter Hexadecimal Number : " );
31- hexadecnum = scan .nextLine ();
32+ hexadecnum = scan .nextLine ();
3233
3334 // first convert hexadecimal to decimal
3435
35- decnum = hex2decimal (hexadecnum );
36+ decnum = hex2decimal (hexadecnum ); //Pass the string to the hex2decimal function and get the decimal form in variable decnum
3637
3738 // convert decimal to octal
3839
You can’t perform that action at this time.
0 commit comments