Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Check str length
- char *bit = bitseq;
- int numBits = 0;
- while (*bit != '\0') {
- numBits++;
- bit++;
- }
- int numWords = (numBits / BITS_PER_WORD) + 1;
- // Goes through input bits, finds value within word, adds to specific word
- for (int i = numWords; i >= 0; i--) {
- b->words[i] = 0; // Clear words for reassignment
- for (int j = BITS_PER_WORD-1; j >= 0; j--) {
- int ref = (numBits - (j + (i*BITS_PER_WORD)))-1;
- printf("R: %d\n", ref);
- // Ref parts:
- // num bits - total number of input bits
- // i*BITS_PER_WORD - total length of all preceeding words
- // j - current word bit position
- // -1 for off by one error
- if (bitseq[ref] == '1') {
- b->words[i] += (1 << j);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement