Last active
December 17, 2015 08:59
-
-
Save k3kaimu/5584263 to your computer and use it in GitHub Desktop.
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 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