[Java]
Package com. jadyer. demo;
/**
* Relations between characters in Java including bit, byte, letter, and Chinese Character
* @ See ================================
* @ See 1 bit = 1 binary data
* @ See 1 byte = 8 bit (range:-128 to + 127)
* @ See 1 letter = 1 byte = 8 bit
* @ See 1 Chinese Character = 2 byte = 16 bit
* @ See ================================
* @ Author Xuan Yu * @ Create Aug 20,201 2 10:28:20 AM
*/Www.2cto.com
Public class ByteDemo {
/**
* @ See console:
* @ See 4
* @ See 4
* @ See ----------------------------
* @ See str = ABab
* @ See 65
* @ See 66
* @ See 97
* @ See 98
* @ See ----------------------------
* @ See name = Xuan Yu
* @ See-48
* @ See-2
* @ See-45
* @ See-15
* @ See ----------------------------
*/
@ SuppressWarnings ("unused ")
Public static void main (String [] args ){
/Byte bb11 = 128; // cannot convert from int to byte
// Byte bb22 =-129; // cannot convert from int to byte
Byte bb11 = 127;
Byte bb22 =-128;
Byte bb33 = 56;
// Byte bb44 = 'xuan'; // error, because: 1 Chinese Character = 2 bytes
// Byte bb55 = 'bb'; // error, because: 'bb' = 2 bytes
Byte bb44 = 'B ';
Byte bb55 = 'B ';
Byte bb66 = 'Z ';
// Int i11 = ""; // 1 int = 32 bit, but int is numeral
// Short ss = 'xuanyu '; // 1 short = 2 byte = 16 bit = 1 Chinese Character
Short ss11 = 'xuan ';
// Char cc11 = 'xuanyu '; // This is not acceptable
// Char cc22 = 'cc'; // This is not acceptable
Char cc11 = 'xuan ';
Char cc22 = 'C ';
String str = "ABab ";
Byte [] data = str. getBytes ();
System. out. println (str. length ());
System. out. println (data. length );
System. out. println ("----------------------------");
System. out. println ("str =" + new String (data ));
For (int I = 0; I <data. length; I ++ ){
System. out. println (data [I]);
}
System. out. println ("----------------------------");
Byte [] name = "". getBytes ();
System. out. println ("name =" + new String (name ));
For (int I = 0; I <name. length; I ++ ){
System. out. println (name [I]);
}
System. out. println ("----------------------------");
}
}