Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unicode

 
Malar Ravi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
______________________________________________________________
char A = '\u0005';
char B = 5;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal");

A = '\u0025';
B = 25;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal");
Output
------
Equal
Not equal
______________________________________________________________
Could someone explain me this code?
Thanks,
Malar.
 
Jennifer Warren
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do a little change in ur code and see it yourself.
char A = '\u0005';
char B = 5;
if (A==B)
System.out.println("Equal "+ A +" " +B);
else
System.out.println("Not equal");
A = '\u0025';
B = 25;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal"+ A +" " +B);

Hope it explains.
Jennifer.
 
Malar Ravi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jennifer,
Thanks for your response. The point which I missed to understand before posting the previous code is that Unicode character is represented by \u followed by 4 hexadecimal digits.
A = '\u0025'
B = 25;
If I replace B=25 with B = 37; (equivalent of 0x0025) then I get "Equal" as output in my previous code.
- Malar.
 
guoyuan zhao
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new one,I don't know how the char convert to Unicode ,
Is your question means that [char 'u00xx']not always equals to [char xx]what is the relations?
 
Cristian Negresco
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
While watching:
char a = '\uxyzw';
every letter will be a HEXA value (0..F)
char b = n;
n it's in decimal.
So if (xyzw)base16 it is equal to (n)base10 so will be the characters.
..Cristian
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guoyuan,
Each Unicode character maps to a specific character based on a given character set or character encoding.
For example, in the standard character set '\u0025' maps to '%', '\u0037' maps to '7', '\u0061' maps to 'a'.
To find out more about how it works see www.unicode.org. For a quicker overview check out this Unicode FAQ and try the the Unicode decoder
Hope that helps.
[This message has been edited by Jane Griscti (edited November 07, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic