Learning to use the system. Collections. Specialized. bitvector32 structure of ASP. NET

Source: Internet
Author: User
The bitvector32 structure only provides 32-bit storage space (the same as int32). It can be used to quickly access boolean values or small integers (such as small integers less than 7 or less than 15 ).
Main members:
 
/* Attribute */data; // integer representation of its 32-bit value, read-only; it can be used to permanently record the status of bitvector32/* Static Method */bitvector32.createmask (); // create maskbitvector32.createsection (); // create bitvector32.sectionbitvector32. tostring (); // return the bit status string of the specified bitvector32 object/* Method */tostring (); // returns the bitwise status string/* The structure related to bitvector32.section also has two attributes */mask; // bit mask offset; // offset
Construction method:
Protected void button1_click (Object sender, eventargs e) {bitvector32 bv1 = new bitvector32 (); // same as new bitvector32 (0); bitvector32 bv2 = new bitvector32 (0 ); // set all 32 bits to 0 bitvector32 bv3 = new bitvector32 (0x0000ff0f); // use an int Value of "bit" bitvector32 bv4 = new bitvector32 (bv3 ); // use the data of another bitvector32 to construct bitvector32 bv5 = new bitvector32 (-1); // you can set the full Bit String S1 = bv1.tostring (); // bitvector32 {00000000000000000000000000000000} string S2 = bv2.tostring (); // bitvector32 {00000000000000000000000000000000} string S3 = bv3.tostring (); // bitvector32 {00000000000000001111111100001111} string S4 = bv4.tostring (); // bitvector32{ 00000000000000001111111100001111} string S5 = bv5.tostring (); // bitvector32{ 11111111111111111111111111111111} textbox1.text = S1 + "\ n" + S2 + "\ n" + S3 + "\ n" + S4 + "\ n" + S5 ;}
Array access:
// If bitvector32 is used to store a number, it can store uint32.maxvalue. protected void button1_click (Object sender, eventargs e) {bitvector32 bv = new bitvector32 (0); BV [1] = true; string S1 = BV. tostring (); // bitvector32 {00000000000000000000000000000001} BV [-1] = false; BV [2] = true; // value string S2 = BV again after all values are cleared. tostring (); // bitvector32 {00000000000000000000000000000010} BV [-1] = false; BV [3] = true; // bitvector32 {00000000000000000000000000000011} string S3 = BV. tostring (); BV [-1] = false; BV [4] = true; // bitvector32 {00000000000000000000000000000100} string S4 = BV. tostring (); BV [-1] = false; BV [5] = true; // bitvector32 {00000000000000000000000000000101} string S5 = BV. tostring (); BV [-1] = false; BV [6] = true; // bitvector32 {00000000000000000000000000000110} string S6 = BV. tostring (); BV [-1] = false; BV [7] = true; // bitvector32 {00000000000000000000000000000111} string S7 = BV. tostring (); BV [-1] = false; BV [int32.maxvalue] = true; // bitvector32 {01111111111111111111111111111111} string S8 = BV. tostring (); textbox1.text = S1 + "\ n" + S2 + "\ n" + S3 + "\ n" + S4 + "\ n" + S5 + "\ n" + S6 +" \ n "+ S7 +" \ n "+ S8 ;}
Access each bit separately:
// Access protected void button#click (Object sender, eventargs e) through a mask (mask) {bitvector32 bv = new bitvector32 (0); int n1 = (INT) math. pow (2, 0); int n2 = (INT) math. pow (2, 1); int N3 = (INT) math. pow (2, 2); int N4 = (INT) math. pow (2, 3); int N5 = (INT) math. pow (2, 4); int n32 = (INT) math. pow (2, 31); BV [N3] = true; string S1 = BV. tostring (); // bitvector32 {00000000000000000000000000000100} BV [N1] = true; BV [n2] = true; BV [N3] = true; BV [N4] = true; BV [N5] = true; BV [n32] = true; string S2 = BV. tostring (); // bitvector32 {10000000000000000000000000011111} BV [-1] = true; // full-position BV [N1] = false; BV [n2] = false; BV [N3] = false; BV [N4] = false; BV [N5] = false; BV [n32] = false; string S3 = BV. tostring (); // bitvector32 {01111111111111111111111111100000} textbox1.text = S1 + "\ n" + S2 + "\ n" + S3 ;}
Bitvector32.createmask ():
<Textarea style = "display: none"> // This is the 32-bit method provided by the designer to access bitvector32bit protected void button#click (Object sender, eventargs E) {bitvector32 bv = new bitvector32 (0); int mk1 = bitvector32.createmask (); // create the first mask or write bitvector32.createmask (0); int Mk2 = bitvector32.createmask (mk1 ); // create Mk2 int mk3 = bitvector32.createmask (Mk2) after mk1; // create mk3 int mk4 = mk3 after Mk2; // int mk5 = bitvector32.createmask (mk4 ); //// mk1 .. values of mk5 are: 1, 2, 4, 8, 16 BV [mk3] = true; string S1 = BV. tostring (); // bitvector32 {00000000000000000000000000000100} BV [mk1] = true; BV [Mk2] = true; BV [mk3] = true; BV [mk4] = true; BV [mk5] = true; string S2 = BV. tostring (); // bitvector32 {00000000000000000000000000011111} BV [-1] = true; // full-position BV [mk1 | Mk2 | mk3 | mk4 | mk5] = false; // you can use "|" or "+" to assign values to several masks at the same time: String S3 = BV. tostring (); // bitvector32 {11111111111111111111111111100000} textbox1.text = S1 + "\ n" + S2 + "\ n" + S3 ;}</textarea>
Bitvector32.createsection ():
// If you want to use 0 .. seven or eight digits, only three binary digits are required. // bitvector32.createsection (n) means that 0 can be set in bitvector32 .. section (segment) protected void button#click (Object sender, eventargs e) {bitvector32 bv = new bitvector32 (0); bitvector32.section sec = bitvector32.createsection (7); string S0, s1, S2, S3, S4, S5, S6, S7; BV [SEC] = 0; S0 = BV. tostring (); // bitvector32 {00000000000000000000000000000000} BV [SEC] = 1; S1 = BV. tostring (); // bitvector32 {00000000000000000000000000000001} BV [SEC] = 2; S2 = BV. tostring (); // bitvector32 {00000000000000000000000000000010} BV [SEC] = 3; S3 = BV. tostring (); // bitvector32 {00000000000000000000000000000011} BV [SEC] = 4; S4 = BV. tostring (); // bitvector32 {00000000000000000000000000000100} BV [SEC] = 5; S5 = BV. tostring (); // bitvector32 {00000000000000000000000000000101} BV [SEC] = 6; S6 = BV. tostring (); // bitvector32 {00000000000000000000000000000110} BV [SEC] = 7; S7 = BV. tostring (); // bitvector32{ 00000000000000000000000000000111} textbox1.text = S0 + "\ n" + S1 + "\ n" + S2 + "\ n" + S3 + "\ n" + S4 + "\ N "+ S5 +" \ n "+ S6 +" \ n "+ S7 ;}
Create multiple sections:
 
// When multiple sections are used, like bitvector32.createmask (), bitvector32.createmask () is based on one and another. protected void button1_click (Object sender, eventargs e) {bitvector32 bv = new bitvector32 (0); bitvector32.section secx = bitvector32.createsection (15); // The first section, which can store 0 .. 15 bitvector32.section Secy = bitvector32.createsection (7, secx); // The Section after secx, which can be stored 0 .. 7 bitvector32.section secz = bitvector32.createsection (15, Secy); // The Section after Secy, which can be stored 0 .. 15 // figure of memory usage at this time: 000000000000000000000 zzzzzzyyyxxxx BV [secx] = 15; BV [Secy] = 0; BV [secz] = 15; string S1 = BV. tostring (); // bitvector32 {00000000000000000000011110001111} BV [secx] = 1; BV [Secy] = 1; BV [secz] = 1; string S2 = BV. tostring (); // bitvector32 {00000000000000000000000010010001} textbox1.text = S1 + "\ n" + S2 ;}
Bitvector32.createsection () returned by bitvector32.section is also a struct:
 
Protected void button1_click (Object sender, eventargs e) {bitvector32 bv = new bitvector32 (0); bitvector32.section secx = forward (15); bitvector32.section Secy = forward (7, secx ); bitvector32.section secz = bitvector32.createsection (15, Secy); textbox1.text = string. format ("{0}, {1}, {2} \ n", secx. mask, Secy. mask, secz. mask); // 15, 7, 15 textbox1.text + = string. format ("{0}, {1}, {2} \ n", secx. offset, Secy. offset, secz. offset); // 0, 4, 7}
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.