Byte和bit
- Byte:字节,一个Byte有8位,1Byte=8bit
- bit:位
- 示例代码
public void click3(View view) { try { String str1 = "A"; String str2 = "我爱你"; byte[] bytes1 = str1.getBytes(); Log.e(TAG, "click3: " + bytes1.length); byte[] bytes2 = str2.getBytes(); Log.e(TAG, "click3: " + bytes2.length); byte[] bytes3 = str2.getBytes("GBK"); Log.e(TAG, "click3: " + bytes3.length); char[] array = str2.toCharArray(); for (char c : array) { int value = c; Log.e(TAG, "click3: " + value); String binaryString = Integer.toBinaryString(value); Log.e(TAG, "click3: " + binaryString); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }