C # Bit Array

Source: Internet
Author: User

Preface

If you need to process many bits, you can use the bitarray class and bitvector32 structure. Bitarray is located in the namespace system. collections, and bitvector32 is located in the namespace system. Collections. Specialized.

 

I. bitarrayClassReference Type

The bitarray class is a reference type and contains an int array. Each 32 bits use a new integer.

My understanding: bitarray is equivalent to a bool array bool []

Official explanation: the bitarray class is a reference type that contains an int array. Every 32 bits use a new integer.

 

Eg

 

Other methods: and (), or (), XOR (), get ()

Eg

 

 

Ii. bitvector32 structure Value Type

If you know the required digits in advance, you can use the bitvector32 structure to replace bitarray. Bitvector32 is more efficient because it is a value type and stores bits on the integer stack. An integer can store 32 bits. * ['Vekt finished] n. vector; carrier; route vt. use radio navigation

 

Eg

 

 

In addition to using the createmask () method to create a mask, you can also define the mask yourself or set multiple digits at a time. The octal 010 is the same as the binary value 1010. It can be expressed in this way

Bits1 [010] = true;

 

 

 

 

 

Differences

The most important difference between the two types is that bitarray can reset the size. If you do not know the number of digits, you can use bitarray, which can contain many digits. Bitvector32 is stack-based, so it is faster. Bitvector32 contains only 32 bits and is stored in an integer.

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.