Um.
You ran this in the debugger and you can;t work it out?
So did I...
It throws the exception at this line:
tempBits.Set(count, false);
Because you rpovide it with a string of eight bits:
writer.Write(ByteHelp.CreateByte("00101010"));
12345678
And only allow for 7 in your bool array:
bool[] boolBits = new bool[7];
So when you try to write the eighth bit
(count == 7)
it doesn't have anywhere to put it...
Change this line:
bool[] boolBits = new bool[7];
To this:
bool[] boolBits = new bool[bits.Length];
And that problem will go away.
But...two things:
1) You do realize that it probably stuffs the bits in the wrong order? So in your example the result will be Hex 54, not Hex 2A?
2) There is a built in function to convert a binary string to a byte:
byte b = Convert.ToByte("00101010", 2);