| | |
Integer to hexdecimal Coversion!!
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 |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






