Encoding and decoding, encoding and decoding

Source: Internet
Author: User

Encoding and decoding, encoding and decoding

Encoding:

Minimum byte Unit

String is a familiar unit.

 

Byte --- "character

String --- "byte

-------------------------------------

Decoding:

String ---> byte []; str. getBytes (charsetName );

 

Byte []-> String; new String (byte [], charsetName );

 

---------------------------------------

Garbled Problem

 

If the number is not changed, you can obtain and decode the number.

 

Bytep [] B = s1.getBytes ("iso8859-1 ");

String s = new String (B, "gbk ");

------------------------------------

China Unicom garbled

 


Coding and decoding in java

New String (strLine. getBytes ("iso8859-1"), "gb2312 ")
Actually, it is easy to understand here
First, convert the string to a byte array .. Converts to the encoding of the iso8859-1 ..
Create a new String with the byte [] array followed by the specific encoding ..
This method is generally used for transcoding .. Garbled characters often appear in JSP
Both Add the filter and use this new String (strLine. getBytes ("iso8859-1"), "gb2312") in the middle to convert the encoding.

What is encoding? What is decoding? Why encoding and decoding?

Encoding converts the content of the source object to a standard format.
Decoding corresponds to encoding. It uses the same standard as encoding to restore the encoding content to the original object content.
Codec was initially designed to encrypt information. It is difficult for people who do not know the encoding standard of the encrypted content to identify it. It has been around for thousands of years.
At present, there are many types of codec, and the main purpose is to exchange information.
In addition to encryption, common applications include character codec, HTML codec, URL codec, email codec, and multimedia codec. Encoding is to meet the transmission requirements, and decoding is to restore the information we can recognize.
For example, character encoding/decoding provides a ing between a series of numbers and characters that people want to see when entering text into a computer. Because there are different languages and texts in the world, we need to encode different texts for processing and transmission through computers.
Another example is multimedia codec. Because there are multiple formats of image sound, they each have their own codec standards.

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.