-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitsbytes.c
More file actions
38 lines (28 loc) · 749 Bytes
/
Copy pathbitsbytes.c
File metadata and controls
38 lines (28 loc) · 749 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include "qic.h"
unsigned int getBit(BYTE *cbuf, unsigned int *bit_pos)
{
/*
* Get the value of the single bit at position bit_pos. This treats the
* entire data region as a bit string.
*
*/
unsigned int byte, shift;
shift = (8 - *bit_pos % 8) - 1;
byte = cbuf[*bit_pos / 8];
(*bit_pos)++;
return (byte & (unsigned int)( 1 << shift )) >> shift;
}
BYTE getByte(BYTE *cbuf, unsigned int *bit_pos)
{
unsigned int i, ret;
for(i = 0, ret=0; i < 8; i++) {
ret = (ret << 1) + getBit(cbuf, bit_pos);
}
/*
if((debug > 2) && (ret > ' '))
fprintf(stderr, "%c ", ret);
*/
if(debug > 2) fprintf(stderr, "0x%x ", ret);
return (BYTE)ret;
}