Java learning notes-character encoding derived from bit operations

Source: Internet
Author: User

A few days ago, I searched for an article about Java bit operations. I saw a program on a blog, which roughly refers to the displacement of strings. Then I said that adding some other operations is an encryption program. Ah ...... I don't know if he has tried it. I think I know that after the data is displaced, the data that is removed will be discarded. Instead, it is replaced by zero or one, only Cyclic Displacement can achieve the effect of moving to and from without data loss, while >>,<<does not carry loops. I tested it myself and found it interesting that the GBK encoding in Chinese seems to be recorded in pinyin, but I have not studied it either, it's just a conjecture from the program.

// Bit operation
Import java. Io .*;

Class javabit ...{
Public static void main (string [] ARGs) throws java. Io. unsupportedencodingexception, ioexception ...{
Bufferedreader bufr = new bufferedreader (New inputstreamreader (system. In ));
System. Out. println ("Enter the string :");
String STR = bufr. Readline ();
Byte [] bitarray = Str. getbytes ();
System. Out. println ("the input string is:" + new string (bitarray, "GBK "));
Int I = 0;
For (; I <bitarray. length; I ++ )...{
Bitarray [I] = (byte) (bitarray [I]> 1 );
}
System. Out. println ("shifted string:" + new string (bitarray, "GBK "));
For (I = 0; I <bitarray. length; I ++ )...{
Bitarray [I] = (byte) (bitarray [I] <1 );
}
System. Out. println ("the returned string is:" + new string (bitarray, "GBK "));

System. Out. println ("String Length:" + I );
System. Out. println (I + "binary representation:" + integer. tobinarystring (I ));
I = I <3;
System. Out. println ("the value after the shift is:" + I );
System. Out. println (I + "binary representation:" + integer. tobinarystring (I ));
}
}

I entered: You are pig 3. After the displacement, the result is: too many characters, too many characters. Of course, other words cannot be connected. Then I moved them back (loss of precision ), that is to say, a 0 is added later, and the result is: It's interesting to plan a Zhu tan competition. Of course, people who know the encoding sequence will not find it interesting.

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.