| | |
Integer to hexdecimal Coversion!!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
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.
Code doesnot compile:
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
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.
Java Syntax (Toggle Plain Text)
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))); } }
Java Syntax (Toggle Plain Text)
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); } }
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
Use Integer.parseInt(java.lang.String,int) with a radix of 16 if you need to convert the hex string back to an int.
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
I managed to split up a 24 bit number by using signed and unsigned shifting of numbers. But i got a question from that part too. Is it true that if we shift a number by 32 bits , all data associated to the number is gone?
Forexample :
00FFFF(in hex)
if i shift it to left by 24 bits and then i shift it back to right by 24 bits the answer i will get is 0000FF.
Sytax used:
int x1;
x=input;
x1 = x<<24;
x1=x1>>>24;
end;
Thanks
Forexample :
00FFFF(in hex)
if i shift it to left by 24 bits and then i shift it back to right by 24 bits the answer i will get is 0000FF.
Sytax used:
int x1;
x=input;
x1 = x<<24;
x1=x1>>>24;
end;
Thanks
Why not find out for yourself? Run those lines (well, check your syntax before you do, because it's incorrect and "end;" isn't a valid statement) with System.out.println() calls after the operations and see what you get.
Your own computer will give you answers to questions like this much quicker and more accurately than anyone on the net.
Your own computer will give you answers to questions like this much quicker and more accurately than anyone on the net.
Last edited by Ezzaral; Jul 7th, 2008 at 12:21 pm.
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
•
•
•
•
Why not find out for yourself? Run those lines (well, check your syntax before you do, because it's incorrect and "end;" isn't a valid statement) with System.out.println() calls after the operations and see what you get.
Your own computer will give you answers to questions like this much quicker and more accurately than anyone on the net.
![]() |
Other Threads in the Java Forum
- Previous Thread: JasperREport not working in .jar file
- Next Thread: How to make a Splash Screen
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






