cottyengland
asked on
How to convert the following string to hex string in Java
How can I convert the following string ....
96 bit string.. stored as 96 bit string
00101111000100100000001100 1001010011 0011000100 1110010011 0100001011 0111111101 1100000111 0000110101
to hex STRING
24 characters..
2F02032533139342DFDC1C35
thank you
96 bit string.. stored as 96 bit string
00101111000100100000001100
to hex STRING
24 characters..
2F02032533139342DFDC1C35
thank you
Actually, that is not going to work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The name of my "source string" is allstring
I cannot get this to compile....
C:\java1_4\bin>javac -classpath cfx.jar;alienrfid.jar HEX_EPC.java
HEX_EPC.java:95: illegal start of expression
public static String binaryToHexString( allstring) {
^
HEX_EPC.java:105: ';' expected
^
2 errors
my code.
public static String binaryToHexString( String allstring) {
StringBuffer retval = new StringBuffer();
for (int i = source.length(); i > 0; i-=4) {
i = i < 0 ? 0 : i;
String temp = Integer.toHexString(Intege r.parseInt (source.su bstring(i - 4, i), 2));
retval.insert(0, temp);
}
return retval.toString();
}
I cannot get this to compile....
C:\java1_4\bin>javac -classpath cfx.jar;alienrfid.jar HEX_EPC.java
HEX_EPC.java:95: illegal start of expression
public static String binaryToHexString( allstring) {
^
HEX_EPC.java:105: ';' expected
^
2 errors
my code.
public static String binaryToHexString( String allstring) {
StringBuffer retval = new StringBuffer();
for (int i = source.length(); i > 0; i-=4) {
i = i < 0 ? 0 : i;
String temp = Integer.toHexString(Intege
retval.insert(0, temp);
}
return retval.toString();
}
why did you change the name of the parameter? if you change the name of a variable you have to change all occurrences of that variable.
ASKER
Yes I did.. sorry. still get the same erros as posted above.
The code I posted was straight out of my IDE. Post the error, I doubt it is EXACTLY the same.
ASKER
public class HEX_EPC implements CustomTag {
public void processRequest( Request request, Response response)
throws Exception
{
****Is it throwing an error because it exists within these brackets?****
}
}
public void processRequest( Request request, Response response)
throws Exception
{
****Is it throwing an error because it exists within these brackets?****
}
}
I posted a METHOD. A method lives at the top level in a class. That means you CAN NOT put a method INSIDE another method. Move it outside of processRequest.
I would suggest that you download http://www.mindview.net/Books/TIJ/ . It's free.
I would suggest that you download http://www.mindview.net/Books/TIJ/ . It's free.
ASKER
Thank You orangehead911, it worked perfectly.
;-D
String hexString = Long.toHexString(val);