convert 8 bit hexdump to 7 bit. The input must be hex codes separated by spaces, supports multiple lines. Ends with eof or empty line.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
8to7/8to7.d

36 lines
833 B

module main;
import std.stdio;
import std.uni : isWhite;
import std.string : strip, empty;
import std.array;
import std.format.read : formattedRead;
void main() {
ubyte b;
while(!stdin.eof()) {
string line = strip(readln());
if (line.empty) { return; }
auto pieces = line.split!isWhite;
foreach (string p; pieces) {
if (1 == formattedRead(p, "%x", &b)) {
writef("%02x ", b & 0x7F);
}
}
write(" ");
foreach (string p; pieces) {
if (1 == formattedRead(p, "%x", &b)) {
b = b & 0x7F;
if (b < 32 || b >= 127) {
write(".");
} else {
writef("%s", cast(char)b);
}
}
}
writeln();
}
}