aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/bitvec.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-12-14 22:23:27 +0100
committerHarald Welte <laforge@gnumonks.org>2009-12-14 22:23:27 +0100
commit7f73a1ac58d6b9f2f8ec793123bf0ee3038fb3a4 (patch)
treef06a49611732216650f56738174c322aa1d4a5f7 /openbsc/src/bitvec.c
parent6c40def716b757a1aa683d9414b2320d3fc20c8a (diff)
bitvec: Introduce bitvec_get_nth_set_bit() function
This is particularly important for determining the ARFCN for cells reported in 04.08 MEAS REP.
Diffstat (limited to 'openbsc/src/bitvec.c')
-rw-r--r--openbsc/src/bitvec.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/openbsc/src/bitvec.c b/openbsc/src/bitvec.c
index 8c82b8776..ad03958f3 100644
--- a/openbsc/src/bitvec.c
+++ b/openbsc/src/bitvec.c
@@ -77,6 +77,22 @@ enum bit_value bitvec_get_bit_pos(struct bitvec *bv, unsigned int bitnr)
return ZERO;
}
+/* get the Nth set bit inside the bit vector */
+unsigned int bitvec_get_nth_set_bit(struct bitvec *bv, unsigned int n)
+{
+ unsigned int i, k = 0;
+
+ for (i = 0; i < bv->data_len*8; i++) {
+ if (bitvec_get_bit_pos(bv, i) == ONE) {
+ k++;
+ if (k == n)
+ return i;
+ }
+ }
+
+ return 0;
+}
+
/* set the bit at a given position inside a bitvec */
int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnr,
enum bit_value bit)