Skip to content

Instantly share code, notes, and snippets.

@tripulse
Created December 17, 2020 06:34
Show Gist options
  • Save tripulse/cf2519a42aa9de2d4bd5db521aa1a079 to your computer and use it in GitHub Desktop.
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.
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