I am getting a string that has been Base64 encoded from a byte[] data, and I have to check the bits inside it.
When I get "AAAB", I decode it to a byte[], and as A = {000000} and B = {000001}, I get [ {00000000} {00000000} {00000001} ].
The thing is that i want to count which bite is 1. In the case above, the bit that is 1 is the number 24, so i want to get 24.
So that is what I wanted to do:
EDITED WITH THE SOLUTION PROPOSED BY SCOTT:
using using System.Linq;
string stringData = "AAAB"; // {000000} {000000} {000000} {000001}
byte[] byteData = Convert.FromBase64String(stringData); // {00000000}{00000000}{00000001}
BitArray bitData = new BitArray(byteData.Reverse().ToArray()); // {100000000000000000000000}
var i = bitData .Length;
foreach (bool bit in bitData )
{
if (bit)
{
//display i, the bit 1
}
j--;
}
Thanks a lot, Scott!