-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitString.cpp
More file actions
32 lines (30 loc) · 792 Bytes
/
Copy pathBitString.cpp
File metadata and controls
32 lines (30 loc) · 792 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
#include "BitString.h"
#include <cstdint>
#include <cstdlib>
bool big_endian() {
uint64_t x = 1;
return ((char*) &x)[7] & 0x1;
}
void bitstring(char* str, char* bytes, size_t size, bool big_endian) {
uint8_t mask;
if (big_endian) {
for (size_t i=0; i<size; i++) {
mask = 0x80;
for (size_t j=0; j<8; j++) {
*str = (bytes[i] & mask) ? '1' : '0';
str++;
mask >>= 1;
}
}
} else {
for (int i = size - 1; i>=0; i--) {
mask = 0x80;
for (size_t j=0; j<8; j++) {
*str = (bytes[i] & mask) ? '1' : '0';
str++;
mask >>= 1;
}
}
}
*str = '\0';
}