To be solved: make lowercase letters uppercase by setting the 6th bit to 0

Source: Internet
Author: User

According to the definition of the UNICODE/ASCII character set, the difference between lowercase letters and uppercase letters is only 32 larger than the latter. So......

1 classUpCase {2      Public Static voidMain (string[] args) {3         Charch;4         5          for(inti = 0; I < 10; i++) {6CH = (Char) (' a ' +i);7 System.out.print (CH);8             9             //This statement turns off the 6th bit.TenCH = (Char) ((int) Ch & 65503);//CH is now uppercase One              ASystem.out.print (ch + ""); -         } -     } the}

The program output is as follows:

AA BB CC dD eE fF gG HH II JJ

The value used in the & statement 65 503 represents 1111 1111 1101 1111 in the binary. Therefore, bitwise AND operation will only allow the 6th bit in ch to be set to 0, while all other bits are unchanged.

To be solved: make lowercase letters uppercase by setting the 6th bit to 0

Related Article

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.