hi ,
i have a simple problem here, that is how can i convert an Decimal integer into Hexadecimal integer and not in Hexadecimal string. I have wrote the following code and managed to get the output from the program. But for a certain reason i cant use it again with the integers, this is because the output hex value is actually a hex string. For my project i have to do calculations using hex values. So plz let me know if there is a class which converts decimal integer into Hexadecimal integer , or any other method which i can use :)
Thanks in Advance.
import java.util.*;
import java.io.*;
public class project {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int x;
System.out.print("\nEnter the integer :");
x = in.nextInt();
System.out.print("\nThe conversion of integer in hex is: "+ (Integer.toHexString(x)));
}
}
Code doesnot compile:
import java.util.*;
import java.io.*;
public class project {
public static void main(String[] args)
{
int x2;/*** I tried using it with String as well ***/
Scanner in = new Scanner (System.in);
int x;
System.out.print("\nEnter the integer :");
x = in.nextInt();
System.out.print("\nThe conversion of integer in hex is: "+(Integer.toHexString(x)));
/******Integer.toHexString(x) gives Hex String of x ***/
x2 = (Integer.toHexString(x))/100;
System.out.print("\nCalculation does occur:"+x2);
}
}
Error:
Output window:
W:\project.java:16: operator / cannot be applied to java.lang.String,int
x2 = (Integer.toHexString(x))/100;
^
1 error
TaskView:
operator / cannot be applied to java.lang.String,int