Learning to use ASP. NET's system. bitconverter class

Source: Internet
Author: User
A static set of bitconverter methods can convert an integer, floating point number, character, or Boolean value into a byte [], which can also be reversed.
Main members:
 
/* Field */bitconverter. islittleendian // Boolean value, indicating the byte sequence of the current system. In Windows, this value is true/* Static Method */bitconverter. getbytes () // obtain the byte [] of the specified parameter. The parameter types can be boolean, Char, double, int16, int32, int64, single, uint16, uint32, and uint64bitconverter. toboolean () // convert byte [] to the Boolean value bitconverter. tochar ()//... bitconverter. todouble () // bitconverter. toint16 () // bitconverter. toint32 () // bitconverter. toint64 () // bitconverter. tosingle () // bitconverter. touint16 () // bitconverter. touint32 () // bitconverter. touint64 () // bitconverter. tostring () // convert byte [] to a string in hexadecimal format. doubletoint64bits () // convert double to int64 to indicate bitconverter. int64bitstodouble () // convert int64 to double
INT-> byte []-> INT:
 
Protected void button1_click (Object sender, eventargs e) {// convert an int to byte [] int n1 = 0x1f2f3f4f; // n1 = 523190095; byte [] BS = bitconverter. getbytes (N1); // view the hexadecimal format of byte [] to indicate string S1 = bitconverter. tostring (BS); // 4f-3f-2f-1f // switch back to int n2 = bitconverter. toint32 (BS, 0); // 523190095 textbox1.text = string. concat (N1, "\ n", S1, "\ n", N2 );}
Double-> byte []-> int64:
Protected void button1_click (Object sender, eventargs e) {double Pi = 3.1415926; byte [] BS = bitconverter. getbytes (PI); // 4a-d8-12-4d-fb-21-09-40 int64 num = bitconverter. toint64 (BS, 0); // 4614256656431372362 textbox1.text = string. concat (PI, "\ n", bitconverter. tostring (BS), "\ n", num);} // use the doubletoint64bits () method to complete the preceding conversion step: protected void button2_click (Object sender, eventargs E) {double Pi = 3.1415926; int64 num = bitconverter. doubletoint64bits (PI); // 4614256656431372362 textbox1.text = string. concat (PI, "\ n", num);} // The conversion below changes the protected void button3_click (Object sender, eventargs e) {double Pi = 3.1415926; int64 num = convert. toint64 (PI); // 3 textbox1.text = num. tostring ();}

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.