Java bit, byte, bit, byte, kanji, character

Source: Internet
Author: User

Package Test;public class Bytetest {    /**      * Byte 8 bits-128-+ 127      * 1 bit = 12 binary data      * 1 byte = 8 bit
   
    * 1 letter = 1 byte = 8 bit (bit)      * 1 kanji = 2 byte = three bit      */public  static void Main (string[] args) {        //TODO A uto-generated method Stub          Byte B1 = 127;          byte b2 = -128;          byte B3 = ' a ';          byte b4 = ' A '; One letter = 1 byte = 8 bit  //      byte B5 = ' AA ';  This is wrong  //      byte B6 = ' Medium '; it's a mistake. 2 bytes 16bit short          s1 = ' ah ';//A Chinese character 2 bytes 16bit Short is a bit of  //
    
     short s2 = ' kanji ';  2 Kanji 4 bytes The three-bit int is the  //      int i1 = ' kanji ';  But int is a numeric type, char is a = 2 byte = a kanji          char c1 = ' Khan ';      byte converts a string string string          = "Chinese";          byte by[] = String.getbytes ();          for (byte b:by) {System.out.println (b);}        String str = new string (by);          System.out.println ("str=" +str); }}
    
   

 

The relationship between bit, byte, bit, byte and Chinese characters


1 bit = 12 binary data
1 byte = 8 bit
1 letter = 1 byte = 8 bit
1 Kanji = 2 byte = + bit


1. Bit: Bits
One binary data 0 or 1, is 1bit;

2. Byte: Byte
The basic unit of measurement for storage space, such as: the definition of VARCHAR (45) in MySQL means 45 bytes;
1 byte = 8 bit

3. A single byte of an English character;
1 letter = 1 byte = 8 bit

4. A kanji account of 2 bytes;
1 Kanji = 2 byte = + bit

5. Punctuation
A>. The input state of Chinese characters, the default is full-width input mode;
B>. In the English input state, the default is the half-width input mode;

C>. In full-width input mode, punctuation is 2 bytes;
D>. In the half-angle input mode, punctuation marks account for 1 bytes;

Therefore: characters in the input state of the characters, accounting for 2 bytes (but do not exclude, they changed the default settings);
The characters in the English input state, accounting for 1 bytes (but do not exclude, they changed the default settings);

 

Java bit, byte, bit, byte, kanji, character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.