我见过人xxd|sed
他们的二进制资源到Cconst uint8_t
数组。它可以是 c++ 化的:
Resource1.h
#include <cstdint>
#include <array>
extern std::array<uint8_t, 1024> resource1;
Resource1.cc
#include "Resource1.h"
const std::array<uint8_t, 1024> resource1 = {
0x42, 0x24, 0x18, ...
...
}
如果您不喜欢正则表达式,可以从这里开始:
hexdump file.bin | sed 's/^[0-9a-f]* \?//;s/ \?\([0-9a-f]\{2\}\) \?/0x\1, /g'
输出类似
0x5b, 0x6b, 0x32, 0x50, 0x69, 0x50, 0x53, 0x64, 0x61, 0x65, 0x63, 0x72, 0x52, 0x68, 0x73, 0x65,
0x6f, 0x70, 0x73, 0x6e, 0x5d, 0x65, 0x3d, 0x20, 0x30, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20,
...