aboutsummaryrefslogtreecommitdiffstats
path: root/util/scan/section.c
blob: 8e499478300ec5f1e575bdeda695793fc8955092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "section.h"

/* shamelessly stolen from dvbsnoop, but modified */
u32 getBits (const u8 *buf, int startbit, int bitlen)
{
	const u8 *b;
	u32 mask,tmp_long;
	int bitHigh,i;

	b = &buf[startbit / 8];
	startbit %= 8;

	bitHigh = 8;
	tmp_long = b[0];
	for (i = 0; i < ((bitlen-1) >> 3); i++) {
		tmp_long <<= 8;
		tmp_long  |= b[i+1];
		bitHigh   += 8;
	}

	startbit = bitHigh - startbit - bitlen;
	tmp_long = tmp_long >> startbit;
	mask     = (1ULL << bitlen) - 1;
	return tmp_long & mask;
}