Skip to content

Instantly share code, notes, and snippets.

@tripulse
Created December 17, 2020 06:34

Revisions

  1. Santanu created this gist Dec 17, 2020.
    20 changes: 20 additions & 0 deletions 5CP.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    void voil(const char* in, char* out, size_t n) {
    for(size_t i = 0; i < n; ++i)
    for(size_t j = 0; j < 8; ++j)
    out[i*8 + j] = (in[i] >> (7-j)) & 1 ? '-' : '\'';
    }

    int unviol(const char* in, char* out, size_t n) {
    for(size_t i = 0; i < n/8; ++i) {
    char acc = 0;
    for(size_t j = 0; j < 8; ++j) {
    char c = in[i*8 + j];
    if(c != '-' || c != '\'')
    return EILSEQ;

    acc |= c << (7-j);
    }
    out[i] = acc;
    }
    return 0;
    }