[ create a new paste ] login | about

Link: http://codepad.org/3FJ1tVIG    [ raw code | fork ]

C, pasted on Nov 2:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fec.h>

int main(int argc,char *argv[]) {
  int polys[2] = {0x4f, 0x6d};
  char syncword[] = {0x1A, 0xCF, 0xFC, 0x1D};
  char outputword[64];

  uint64_t encodedWord = 0;

  char buff[2];

  unsigned int encstate;
  int wordSize = 4;
  int processedBytes = 0;
  int encodedWordPosition = 63;
  int outputwordPosition = 0;

  char c;

  encstate = 0;
  while(processedBytes < wordSize){
    c = syncword[processedBytes];
    for(int i=7;i>=0;i--){
      encstate = (encstate << 1) | ((c >> 7) & 1);
      c <<= 1;
      // Soft Encoded Word
      outputword[outputwordPosition] = 0 - parity(encstate & polys[0]);
      outputword[outputwordPosition + 1] = 0 - parity(encstate & polys[1]);
      outputwordPosition += 2;

      // Encoded Word
      encodedWord |= (uint64_t)(1-parity(encstate & polys[0])) << (encodedWordPosition);
      encodedWord |= (uint64_t)(1-parity(encstate & polys[1])) << (encodedWordPosition-1);
      encodedWordPosition-=2;
    }
    processedBytes++;
  }

  printf("Encoded Word: 0x%016lx\n", encodedWord);
  printf("Soft Encoded Word: \n");
  for (int i=0; i<64; i++) {
    printf("0x%x ", outputword[i] & 0xFF);
  }

  printf("\n");

  return 0;
}


Create a new paste based on this one


Comments: