Conversion method between binaries in Java

Source: Internet
Author: User

1  Public classCode {2 3      Public Static voidMain (string[] args)throwsexception{4         //TODO auto-generated Method Stub5String s= "Practice By Yourself";6         byte[] byte1=s.getbytes ();//Converts a string to a character array, using the project's default encoding7          for(byteb:byte1) {8             //The byte is displayed in 16 binary mode9System.out.print (integer.tohexstring (B&0XFF) + "");Ten         } One System.out.println (); A     //jbk Chinese occupies two bytes, English occupies one byte -     byte[] Byte2=s.getbytes ("GBK"); -      for(byteb:byte2) { theSystem.out.print (integer.tohexstring (B&0XFF) + ""); -     } - //one of the utf-8 Chinese occupies three bytes, English occupies one byte - System.out.println (); +     byte[] Byte3=s.getbytes ("Utf-8"); -      for(byteb:byte3) { +System.out.print (integer.tohexstring (B&0XFF) + ""); A     } at     //Java is a double-byte encoding, UTF-16BE encoding -     //where Chinese occupies two bytes, English occupies two bytes - System.out.println (); -     byte[] Byte4=s.getbytes ("Utf-16be"); -      for(byteb:byte4) { -System.out.print (integer.tohexstring (B&0XFF) + ""); in     } - System.out.println (); toString st1=NewString (Byte4, "Utf-16be"); + System.out.print (ST1); -      the System.out.println (); *     byte[] Byte5=s.getbytes ("Us-ascii"); $      for(byteb:byte5) {Panax NotoginsengSystem.out.print (integer.tohexstring (B&0XFF) + ""); -     } the     } +  A}

Conversion method between binaries in Java

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.