author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Wed, 08 Feb 2023 13:01:34 +0200 | |
changeset 749 | 29a81e7e22f6 |
parent 359 | c0ac856d2e4b |
permissions | -rw-r--r-- |
#include <stdlib.h> #include <stdio.h> int main() { int ch; int buf = 0; int off = 0; while ((ch = getchar()) != EOF) { /* printf("ch: %c\n", ch); */ if (off == 0) { buf = ch & 0x7f; off = 7; } else { int remain = 8 - off; int hi = ch & ((1<<remain) - 1); buf |= hi << off; printf("%02x", buf); buf = (ch & 0x7f) >> remain; off = 7 - remain; } } if (off > 0) { printf("%02x", buf); } return EXIT_SUCCESS; }