M
moonhkt
Hi All
Why using utf-8, the hex value return 51cc and 6668 ?
od -cx utf8_file01.text
22e5 878c e699 a822 with " befor and after
http://www.fileformat.info/info/unicode/char/51cc/index.htm
http://www.fileformat.info/info/unicode/char/6668/index.htm
Output
......
101 ? 20940 HEX=51cc BIN=101000111001100
102 ? 26216 HEX=6668 BIN=110011001101000
Java program
import java.nio.charset.Charset ;
import java.io.*;
import java.lang.String.*;
import java.lang.Integer.*;
public class read_utf_line {
public static void main(String[] args) {
File aFile = new File("utf8_file01.text");
try {
System.out.println(aFile);
String str = "";
String hexstr = "";
String bystr = "";
int stlen= 0;
Integer val=0;
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(aFile), "UTF8"));
while (( str = in.readLine()) != null )
{ stlen = str.length();
System.out.println(str.length());
for (int i = 0;i < stlen;++i) {
val = str.codePointAt(i);
hexstr = Integer.toHexString(val);
bystr = Integer.toBinaryString(val);
System.out.println(i + " " + str.substring(i,i+1)
+ " " + str.codePointAt(i)
+ " HEX=" + hexstr
+ " BIN=" + bystr
);
}
}
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
}
}
Why using utf-8, the hex value return 51cc and 6668 ?
od -cx utf8_file01.text
22e5 878c e699 a822 with " befor and after
http://www.fileformat.info/info/unicode/char/51cc/index.htm
http://www.fileformat.info/info/unicode/char/6668/index.htm
Output
......
101 ? 20940 HEX=51cc BIN=101000111001100
102 ? 26216 HEX=6668 BIN=110011001101000
Java program
import java.nio.charset.Charset ;
import java.io.*;
import java.lang.String.*;
import java.lang.Integer.*;
public class read_utf_line {
public static void main(String[] args) {
File aFile = new File("utf8_file01.text");
try {
System.out.println(aFile);
String str = "";
String hexstr = "";
String bystr = "";
int stlen= 0;
Integer val=0;
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(aFile), "UTF8"));
while (( str = in.readLine()) != null )
{ stlen = str.length();
System.out.println(str.length());
for (int i = 0;i < stlen;++i) {
val = str.codePointAt(i);
hexstr = Integer.toHexString(val);
bystr = Integer.toBinaryString(val);
System.out.println(i + " " + str.substring(i,i+1)
+ " " + str.codePointAt(i)
+ " HEX=" + hexstr
+ " BIN=" + bystr
);
}
}
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
}
}