0

I want Convert Byte to fixed size (size = 8) bit array

Want Behavior:

var bits = GetBits(0x00); // returned [0,0,0,0,0,0,0,0]

bits = GetBits(0x01); // returned [1,0,0,0,0,0,0,0]

bits = GetBits(0x0A); // returned [0,1,0,1,0,0,0,0]

I used below code but it didn't return what I want.

BitArray bits = new BitArray(byte);
1
  • BitArray' constructor takes a length not a byte to convert. Commented Nov 15, 2023 at 6:37

1 Answer 1

1

You're using the wrong constructor.

Try this:

BitArray bits = new BitArray(new byte[] { 12 });

BitArray

The constructor you're using is saying how long you want the bit array to be.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.