Created
December 17, 2020 06:34
-
-
Save tripulse/cf2519a42aa9de2d4bd5db521aa1a079 to your computer and use it in GitHub Desktop.
5IGI0 Communication Protocol. Byte data from/to ASCII compatible Violeur format payload conversion subroutines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment