Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting hexadecimal to string

Status
Not open for further replies.

chirpyform

Programmer
Jun 20, 2003
202
FR
Has anyone got any code to convert a string of hexadecimal to a string normal.

Ex

3c -> 60 -> '<'

in this case I pass "3c" and I would like "<" returned to me


Thanks Chris
 
This is from a HEX editor I wrote. I have a binary file ("in") that I read in and display 16 bytes per line:
Code:
		int nbytread=in.read(datain,0,sz);
		String datast = new String(datain);
		for (int i=0; i<numlines; i++) {
			valst="";
			bi = 0;
			for (int j=offset+(i*16);j<offset+(i*16)+16;j++) {
				tempst=Integer.toHexString(datain[j]);
				val1 = tempst.length()-2;
				if (val1<0) {
					val1=0;
					tempst="0"+tempst;
				}
				valst=valst+tempst.substring(val1);
				valb[B][I]=datain[j];
				bi++;
			}
			tempst=datast.substring(i*16,i*16+16);
			String badd = String.valueOf(offset+i*16);
			while (badd.length()<5) {
				badd = badd+" ";
			}
			lst1.add(badd+" "+valst+"     :"+tempst);
		}

Bob Rashkin
rrashkin@csc.com
 
Or something like:
Code:
public class Test {

    public static void main(String[] args) throws Exception {
        String hex = args[0];
        char character = convert(hex);
        System.out.println(hex+" = "+character);
    }

    public static char convert(String hex) throws Exception {
        return (char) Integer.parseInt(hex, 16);
    }
}
Cheers, Neil :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top