-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshrinker.cpp
More file actions
38 lines (32 loc) · 744 Bytes
/
shrinker.cpp
File metadata and controls
38 lines (32 loc) · 744 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
// This program packs padded 4-bit data. I used it in an FPGA project.
#include <array>
#include <bitset>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
int main(int argc, char **argv) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <in> <out>\n";
return 1;
}
std::ifstream ifstream(argv[1]);
std::stringstream sstream;
sstream << ifstream.rdbuf();
std::ofstream ofstream(argv[2]);
uint8_t temp = 0;
bool first = true;
for (const uint8_t byte: sstream.str()) {
if (first) {
temp = (byte & 0xf) << 4;
first = false;
} else {
ofstream << static_cast<char>(temp | (byte & 0xf));
first = true;
}
}
}