C # byte array to string, get definition and BASE64 encoding

Source: Internet
Author: User
Tags array to string base64 get definition

The BASE64 encoding requires the conversion of 3 8-bit bytes (3*8=24) into 4 6-bit bytes (4*6=24), followed by 6 two in front of 0 bits, forming a 8-bit byte form. If the remaining characters are less than 3 bytes, then 0 is populated with the output character using ' = ', so there may be 1 or 2 ' = ' At the end of the encoded text output. To ensure the output of the encoded bit-readable characters, BASE64 developed an encoding table for uniform conversion. The size of the encoded table is 2^6=64, which is also the origin of the Base64 name.

BASE64 Encoding Table:

Code Value character Code Value character Code Value character Code Value character
0 A 16 Q 32 G 48 W
1 B 17 R 33 H 49 X
2 C 18 S 34 I 50 Y
3 D 19 T 35 J 51 Z
4 E 20 U 36 K 52 0
5 F 21st V 37 L 53 1
6 G 22 W 38 M 54 2
7 H 23 X 39 N 55 3
8 I 24 Y 40 O 56 4
9 J 25 Z 41 P 57 5
10 K 26 A 42 Q 58 6
11 L 27 B 43 R 59 7
12 M 28 C 44 S 60 8
13 N 29 D 45 T 61 9
14 O 30 E 46 U 62 +
15 P 31 F 47 V 63 /

     Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidForm1_Load (Objectsender, EventArgs e) {TextBox1.Text="X2009 China"; }        Private voidtextBox1_TextChanged (Objectsender, EventArgs e) {            byte[] bs =Encoding.UTF8.GetBytes (TextBox1.Text); TextBox2.Text=bitconverter.tostring (BS); stringresult ="{"; foreach(byteBinchBS) result+="0x"+ b.tostring ("X2") +","; Result= result. TrimEnd (',') +"}"; TextBox3.Text=result; Textbox4.text=convert.tobase64string (BS); }    }

C # byte array to string, get definition and BASE64 encoding

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.