Skip to content

Instantly share code, notes, and snippets.

@k3kaimu
Last active December 17, 2015 08:59
Show Gist options
  • Save k3kaimu/5584263 to your computer and use it in GitHub Desktop.
Save k3kaimu/5584263 to your computer and use it in GitHub Desktop.
void oct2bin(const char *oct, int n, int nbit, char *bin, int skipLast, int flip)
{
int i, cnt = 0, skip = 0;
const static char octlist[8][3]={{1,1,1},{1,1,-1},{1,-1,1},{1,-1,-1},{-1,1,1},{-1,1,-1},{-1,-1,1},{-1,-1,-1}}; /* 0=>1, 1=>-1 */
if(n * 3 >= nbit)
skip = skipLast ? nbit : (n * 3 - nbit);
for(i = 0; i < n * 3; ++i){
if(skipLast){
if(!(i < skip))
continue;
}else{
if(!(i >= skip))
continue;
}
bin[cnt] = octlist[oct[i / 3] - '0'][cnt % 3];
++cnt;
}
if(flip) fliparrayc(bin, nbit, bin);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment