blob: a4924a00014403658ac79b81b899317a346e9de0 (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "bit.h"
u64 flp2(u64 x){
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
x |= (x >> 32);
return x - (x >> 1);
}
u32 flp2_32(u32 x){
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return x - (x >> 1);
}
u64 clp2(u64 x){
x -= 1;
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
x |= (x >> 32);
return x + 1;
}
u32 clp2_32(u32 x){
x -= 1;
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return x + 1;
}
void _bitstofile(void const * const ptr, size_t const size, FILE *fp){
unsigned char *b = (unsigned char*)ptr;
for(int i = size-1; i >= 0; i--){
for(int j = 7; j >= 0; j--){
unsigned char byte = ((b[i] >> j) & 1) ? '1' : '0';
fputc(byte, fp);
}
if(i != 0) fputc(' ', fp);
}
}
|