
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialThe BitArray collection handles a compact matrix of bit values. These bit values are represented as boolean values where true indicates 1 and false indicates 0.
The different constructors and their description is given as follows:
Constructors | Description |
|---|---|
BitArray (BitArray) | This constructor initializes a new instance of the BitArray class that contains the bit values copied from the specified BitArray collection. |
BitArray (Boolean []) | This constructor initializes a new instance of the BitArray class that contains the bit values copied from the specified Boolean array. |
BitArray (Byte []) | This constructor initializes a new instance of the BitArray class that contains the bit values copied from the specified byte array. |
BitArray (Int32) | This constructor initializes a new instance of the BitArray class that can contain the specified number of bit values, initially set to false. |
BitArray (Int32, Boolean) | This constructor initializes a new instance of the BitArray class that can contain the specified number of bit values, initially set to the specified value. |
BitArray (Int32 []) | This constructor initializes a new instance of the BitArray class that contains the bit values copied from the specified 32-bit integer array. |
Table: Constructors in BitArray in C#
Source: MSDN
The different properties and their description is given as follows:
Properties | Description |
|---|---|
Count | This property gets the number of elements included in BitArray. |
IsReadOnly | This property gets a value that indicates whether BitArray is read-only. |
IsSynchronized | This property gets a value that indicates whether access to the BitArray interface is synchronized (it is thread safe). |
Item [Int32] | This property gets or sets the value of the bit that is in a specific BitArray position |
Length | This property gets or sets the number of BitArray elements. |
SyncRoot | This property gets an object that can be used to synchronize access to BitArray. |
Table: Properties in BitArray in C#
Source: MSDN
The different methods and their description is given as follows:
Methods | Description |
|---|---|
And(Bit Array) | This method performs the AND operation bit by bit between the elements of the current BitArray object and the corresponding elements of the specified array. The current BitArray object will be modified to store the result of the bitwise AND operation |
Clone() | This method creates a surface copy of the BitArray collection. |
CopyTo( Array, Int32) | This method copies the entire BitArray into a compatible one-dimensional array, starting at the specified index of the target array. |
Equals(Object) | This method determines whether the specified object is equal to the current object. |
Get(Int32) | This method gets the value of the bit in a specific BitArray position |
GetEnumerator() | This method returns an enumerator that iterates through the BitArray collection. |
GetHashCode() | This method serves as the default hash function. |
GetType() | This method gets the Type of the current instance. |
MemberwiseClone() | This method creates a surface copy of the current Object. |
Not() | This method inverts all the bit values that are in the current BitArray collection, so that the elements set in true change to false and the elements set in false change toa true. |
Or(Bit Array) | This method performs the bitwise OR operation between the elements of the current BitArrayobject and the corresponding elements of the specified array. The current BitArray object will be modified to store the result of the bitwise OR operation. |
Set(Int32, Boolean) | This method sets the bit located at a specific BitArray position to the specified value |
SetAll (Boolean) | This method sets all BitArray bits to the specified value. |
ToString() | This method returns a string that represents the current object. |
Xor(Bit Array) | This method performs the exclusive OR bitwise operation between the elements of the current BitArray object against the corresponding elements of the specified array. The current BitArray object will be modified to store the result of the bitwise exclusive OR operation. |
Table: Methods in BitArray in C#
Source: MSDN
Some of the BitArray operations are given as follows:
A BitArray can be created using new. Then the appropriate boolean values can be inserted into a BitArray. The program that demonstrates this is given as follows:
using System;
using System.Collections;
namespace BitArrayDemo
{
class Example
{
static void Main(string[] args)
{
BitArray bArr = new BitArray(5);
bArr.Set(0, true);
bArr.Set(1, false);
bArr.Set(2, true);
bArr.Set(3, true);
bArr.Set(4, false);
for (int i = 0; i < bArr.Count; i++)
{
Console.Write(bArr [i]);
Console.Write(" ");
}
}
}
}
Source Code: Program to create BitArray in C#
The output of the above program is as follows:
True False True True FalseThe And() method performs the AND operation bit by bit between the elements of the current BitArray and the corresponding elements of the BitArray that is specified. The program that demonstrates this is given as follows:
using System;
using System.Collections;
namespace BitArrayDemo
{
class Example
{
static void Main(string[] args)
{
BitArray bArr1 = new BitArray(5);
BitArray bArr2 = new BitArray(5);
bArr1.Set(0, true);
bArr1.Set(1, false);
bArr1.Set(2, true);
bArr1.Set(3, true);
bArr1.Set(4, false);
bArr2.Set(0, true);
bArr2.Set(1, true);
bArr2.Set(2, false);
bArr2.Set(3, true);
bArr2.Set(4, false);
Console.WriteLine("BitArray 1");
for (int i = 0; i < bArr1.Count; i++)
{
Console.Write(bArr1[i]);
Console.Write(" ");
}
Console.WriteLine();
Console.WriteLine("BitArray 2");
for (int i = 0; i < bArr2.Count; i++)
{
Console.Write(bArr2[i]);
Console.Write(" ");
}
bArr1.And(bArr2);
Console.WriteLine();
Console.WriteLine("BitArray after AND operation");
for (int i = 0; i < bArr1.Count; i++)
{
Console.Write(bArr1[i]);
Console.Write(" ");
}
}
}
}
Source Code: Program to demonstrate AND operation in BitArray in C#
The output of the above program is as follows:
BitArray 1
True False True True False
BitArray 2
True True False True False
BitArray after AND operation
True False False True False
The Or() method performs the OR operation bit by bit between the elements of the current BitArray and the corresponding elements of the BitArray that is specified. The program that demonstrates this is given as follows:
using System;
using System.Collections;
namespace BitArrayDemo
{
class Example
{
static void Main(string[] args)
{
BitArray barr1 = new BitArray(5);
BitArray barr2 = new BitArray(5);
barr1.Set(0, true);
barr1.Set(1, false);
barr1.Set(2, true);
barr1.Set(3, true);
barr1.Set(4, false);
barr2.Set(0, true);
barr2.Set(1, true);
barr2.Set(2, false);
barr2.Set(3, true);
barr2.Set(4, false);
Console.WriteLine("BitArray 1");
for (int i = 0; i < barr1.Count; i++)
{
Console.Write(barr1[i]);
Console.Write(" ");
}
Console.WriteLine();
Console.WriteLine("BitArray 2");
for (int i = 0; i < barr2.Count; i++)
{
Console.Write(barr2[i]);
Console.Write(" ");
}
barr1.Or(barr2);
Console.WriteLine();
Console.WriteLine("BitArray after OR operation");
for (int i = 0; i < barr1.Count; i++)
{
Console.Write(barr1[i]);
Console.Write(" ");
}
}
}
}
Source Code: Program to demonstrate OR operation in BitArray in C#
The output of the above program is as follows:
BitArray 1
True False True True False
BitArray 2
True True False True False
BitArray after OR operation
True True True True False
The Not() method inverts all the elements in the specified BitArray so the true elements are converted to false and the false elements are converted to true. The program that demonstrates this is given as follows:
using System;
using System.Collections;
namespace BitArrayDemo
{
class Example
{
static void Main(string[] args)
{
BitArray barr = new BitArray(5);
barr.Set(0, true);
barr.Set(1, false);
barr.Set(2, true);
barr.Set(3, true);
barr.Set(4, false);
Console.WriteLine("BitArray");
for (int i = 0; i < barr.Count; i++)
{
Console.Write(barr[i]);
Console.Write(" ");
}
barr.Not();
Console.WriteLine();
Console.WriteLine("BitArray after NOT operation");
for (int i = 0; i < barr.Count; i++)
{
Console.Write(barr[i]);
Console.Write(" ");
}
}
}
}
Source Code: Program to demonstrate NOT operation in BitArray in C#
The output of the above program is as follows:
BitArray
True False True True False
BitArray after NOT operation
False True False False True
Use the IsReadOnly property to check whether the BitArray is ReadOnly or not. If a collection is ReadOnly, then you won’t be able to add new elements to it.
Let us see an example that checks whether the BitArray is ReadOnly or not:
using System;
using System.Collections;
namespace BitArrayDemo
{
class Example
{
static void Main(string[] args)
{
BitArray bArr = new BitArray(5);
bArr.Set(0, true);
bArr.Set(1, false);
bArr.Set(2, true);
bArr.Set(3, true);
for (int i = 0; i < bArr.Count; i++)
{
Console.Write(bArr [i]);
Console.Write(" ");
}
Console.WriteLine("\nIsReadOnly? " + bArr.IsReadOnly);
}
}
}
Source Code: Program to check whether the BitArray is ReadOnly or not in C#
The above program gives the following output:
True False True True False
IsReadOnly? False
To get the length of the BitArray elements, use the Length property. Let us see an example:
using System;
using System.Collections;
public class Example {
public static void Main() {
BitArray bArr1 = new BitArray(15);
BitArray bArr2 = new BitArray(5);
bArr2.Set(0, true);
bArr2.Set(1, false);
bArr2.Set(2, true);
bArr2.Set(3, true);
bArr2.Set(4, false);
for (int i = 0; i < bArr2.Count; i++)
{
Console.Write(bArr2 [i]);
Console.Write(" ");
}
Console.WriteLine( "\nLength: {0}", bArr1.Length );
Console.WriteLine( "Length: {0}", bArr2.Length );
}
}
Source Code: Program to get the length of the BitArray elements in C#
The above program gives the following output:
True False True True False
Length: 15
Length: 5
To get the count of the elements in BitArray, use the Count property. Let us see an example:
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray bArr1 = new BitArray( 10 );
BitArray bArr2 = new BitArray(5);
bArr2.Set(0, true);
bArr2.Set(1, false);
bArr2.Set(2, true);
bArr2.Set(3, true);
bArr2.Set(4, false);
for (int i = 0; i < bArr2.Count; i++)
{
Console.Write(bArr2 [i]);
Console.Write(" ");
}
Console.WriteLine( "\nCount: {0}", bArr1.Count );
Console.WriteLine( "Count: {0}", bArr2.Count );
}
}
Source Code: Program to get the count of the elements in BitArray in C#
The above program gives the following output:
True False True True False
Count: 10
Count: 5
In a BitArray collection, you may need to fetch a value. For that, the following is the code. Here, we are displaying a value from the BitArray elements:
using System;
using System.Collections;
public class Example {
public static void Main() {
BitArray bArr1 = new BitArray(15);
BitArray bArr2 = new BitArray(5);
bArr2.Set(0, true);
bArr2.Set(1, false);
bArr2.Set(2, true);
bArr2.Set(3, true);
bArr2.Set(4, false);
for (int i = 0; i < bArr2.Count; i++)
{
Console.Write(bArr2 [i]);
Console.Write(" ");
}
Console.WriteLine( "\nLength: {0}", bArr1.Length );
Console.WriteLine( "Length: {0}", bArr2.Length );
bool s = bArr2[3];
Console.WriteLine("4th element ="+s);
}
}
Source Code: Program to fetch a value from a BitArray collection in C#
The above program generated the following output:
True False True True False
Length: 15
Length: 5
4th element =True