Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting C# byte to BitArray

Tags:

c#

byte

bitarray

Is there any predefined function available to convert a byte into BitArray?

One way would be to inspect every bit of the byte value and then perform bitwise operation. I was wondering if there is any way which is more straightforward than this.

like image 488
Shamim Hafiz - MSFT Avatar asked Jun 26 '12 09:06

Shamim Hafiz - MSFT


People also ask

What is type conversions in C?

In C programming, we can convert the value of one data type ( int, float , double , etc.) to another. This process is known as type conversion.

Can you convert data types in C?

We can use the process of type casting to convert the character (char) data type to the int (integer) data type in C. When we are performing a conversion between these two, the resultant value would be an integer (int) data type. It is because the int data type is comparatively bigger than the char data type in C.

How many conversion are there in C?

There are two type of type conversion: implicit and explicit type conversion in C.

What is a cast in C?

What is Type casting in C? In C, When you convert the data type of a variable to another data type then this technique is known as typecasting. Let's say that you want to store a value of int data type into a variable of float data type. Then you can easily do this with the help of typecasting.


1 Answers

Yes, using the appropriate BitArray() constructor as described here:

var bits = new BitArray(arrayOfBytes);

You can call it with new BitArray(new byte[] { yourBite }) to create an array of one byte.

like image 170
CodeCaster Avatar answered Sep 28 '22 19:09

CodeCaster