d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java - Hex To Unicode
Add Reply New Topic New Poll
Member
Posts: 27,514
Joined: Feb 12 2006
Gold: 8,035.01
Apr 10 2013 06:11pm
Hey guys,
I have to to do following:
Create the hex code for a number (in my case 48) and give a out print like this:
System.out.println(number + hex + unicode)

What I got so far:
Code
public class Teil1 {

public static void main(String[] args) {
 
 int x;
 x = 48;
 
 System.out.println("48" + Integer.toHexString(x) + UNICODE);
 }
}


So how do I get the unicode into this?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 10 2013 06:23pm
convert to char and back to string
Member
Posts: 27,514
Joined: Feb 12 2006
Gold: 8,035.01
Apr 10 2013 11:28pm
Quote (carteblanche @ 11 Apr 2013 01:23)
convert to char and back to string


could you show it to me on a example?

that's what I got so far:

Code
import java.lang.Integer;

public class Teil1 {
    static String toHex(int zahl){
        return Integer.toHexString(zahl);
    }

    static String toUnicode(int zahl){
        String zusatz= "";
        String hex = Integer.toHexString(zahl);
        for(int i=4; i>Integer.toHexString(zahl).length(); i--){
            zusatz = zusatz + "0";
        }
        String erg = zusatz+hex;
        return erg;
    }

    public static void main(String[] args) {
        int[] zahl= new int[3];
        zahl[0]=48;
        zahl[1]=65;
        zahl[2]=122;

        for(int item: zahl){
         
         System.out.println(item + " " + toHex(item) + " \\u"+ toUnicode(item) );
        }
    }
}


This post was edited by Samuray on Apr 10 2013 11:38pm
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Apr 11 2013 07:10am
System.out.println(x+ " " + Integer.toHexString( x) + " " + (char)x);
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll