0
다음 BitArray combinedResults = searchBitArray.And (genreBitArray); 100100110000비트 배열에서 긍정적 인 비트 인덱스 가져 오기
어떻게 모든 긍정적 인 것들의 인덱스를 얻을 수 있습니다 즉 긍정적 인 비트를 포함
?
다음 BitArray combinedResults = searchBitArray.And (genreBitArray); 100100110000비트 배열에서 긍정적 인 비트 인덱스 가져 오기
어떻게 모든 긍정적 인 것들의 인덱스를 얻을 수 있습니다 즉 긍정적 인 비트를 포함
?
가 여기에 먼저 확실히 빈민가, 그것은에 균열 :
이BitArray ba = new BitArray(new bool[] {true,false,false,true,false,false,true,true,false,false,false,false});
List<int> pos = new List<int>();
for (int i = 0; i < ba.Length; i++)
{
if (ba[i])
pos.Add(i);
}
당신에게 당신은 ba.Length에서 시작할 수 0, 3, 6, 7을 포함하는 목록을 줄 것이다 그 -에 이르기까지 1 및 감소를 오른쪽에서 왼쪽으로 읽어야 할 경우 0입니다. 편집
: 확장 방법에 싸여, 단지 이유는
void Main()
{
BitArray ba = new BitArray(new bool[] {true,false,false,true,false,false,true,true,false,false,false,false});
List<int> positives = ba.GetBitPositions(true);
List<int> negatives = ba.GetBitPositions(false);
}
public static class BitArrayExtensions
{
public static List<int> GetBitPositions(this BitArray ba, bool MatchCondition)
{
List<int> pos = new List<int>();
for (int i = 0; i < ba.Length; i++)
{
if (ba[i] == MatchCondition)
pos.Add(i);
}
return pos;
}
}
멋진 작품 그 위대한 감사합니다 – StevieB
어떻게 나중에 비트 위치를 사용해야합니까? 제공된 배열을 통해 보려는 결과의 유형과 해당 결과로 수행 할 수있는 결과의 예를 들려 줄 수 있습니까? –
기본적으로 나는 (Lucene.NET) 검색 인덱스에 인덱스를 제공하기 때문에 양수 비트의 모든 인덱스를 찾고 싶습니다. 기본적으로 화면에 긍정적 인 색인을 모두 표시하려면 검색 결과가 – StevieB
이니 무엇을 원하겠습니까?을 나열 하시겠습니까? –