Golang characters, strings of things

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

As you can see from the code below, R is essentially Int32, takes up 4 bytes, the value is 25105;s is a string, takes 3 bytes, and the value is e68891.

The inference R should be Unicode encoded, and S is UTF8 encoded.

Package main           Import (    "FMT")           func Main () {    r: = ' I '     fmt. Printf ("%t\n", R)    //%!t (int32=25105)               s: = "I"    fmt. Printf ("%t,%d%x\n", S, Len (s), s)    //%!t (string= me) 3 e68891               FMT. Printf ("%b\n", Int32 (R))    //110001000010001    /0000 0000 0000 0000 0110 0010 0001 0001                   for _, B: = range [] Byte (s) {        fmt. Printf ("%b\n", b)    }    //11100110    //10001000    //10010001}

Now print out the binary values for comparison, organized as follows:

0000 0000 0000 0000 0110 0010 0001 0001//R          1110 0110 1001 0001//S

Then convert S to r, i.e. UTF8 to Unicode

          1110 0110 1001 0001//s 0110 0001   //s UTF8-Unicode          0000 0000 0110 0010 0001 0 001//s UTF8, unicode0000 0000 0000 0000 0110 0010 0001 0001//R

The conversion succeeds in concluding that R is Unicode encoding s is UTF8 encoded

Golang and Java characters are Unicode encoded strings are UTF8 encoded

Bottom These things must be understood, otherwise it will often harm.

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.