Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1.     //Check str length
  2.     char *bit = bitseq;
  3.     int numBits = 0;
  4.     while (*bit != '\0') {
  5.         numBits++;
  6.         bit++;
  7.     }
  8.  
  9.     int numWords = (numBits / BITS_PER_WORD) + 1;
  10.     // Goes through input bits, finds value within word, adds to specific word
  11.     for (int i = numWords; i >= 0; i--) {
  12.         b->words[i] = 0;                    // Clear words for reassignment
  13.         for (int j = BITS_PER_WORD-1; j >= 0; j--) {
  14.             int ref = (numBits - (j + (i*BITS_PER_WORD)))-1;
  15.             printf("R: %d\n", ref);
  16.             // Ref parts:
  17.             // num bits - total number of input bits
  18.             // i*BITS_PER_WORD - total length of all preceeding words
  19.             // j - current word bit position
  20.             // -1 for off by one error
  21.             if (bitseq[ref] == '1') {
  22.                 b->words[i] += (1 << j);
  23.             }
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement