Пример #1
0
/* Returns true if two 32 bit values match */
static inline bool
match_32(uint8_t *a, uint8_t *b) {
    uint32_t *a1 = (uint32_t *) a;
    uint32_t *b1 = (uint32_t *) b;
    FILE *file;
    file = fopen("file.txt","a+"); 
    fprintf(file,"%s","Now printing A "); /*writes*/
    printbits(*a1,file);
    fprintf(file,"%s","\n"); /*writes*/
    fprintf(file,"%s","Now printing B "); /*writes*/
    printbits(*b1,file);
    if(*a1 == *b1){
    fprintf(file,"%s","They match!"); /*writes*/

    }
   else {
    fprintf(file,"%s","They DONT match!"); /*writes*/

}
    fprintf(file,"%s","\n"); /*writes*/
    fprintf(file,"%s","\n"); /*writes*/
    
    fclose(file); /*done!*/ 
    return (*a1 == *b1);
}
Пример #2
0
void printfloat(float f)
{
    int32_t t = floatToBits(f);
    printbits(t, 31, 31);
    printbits(t, 30, 23);
    printbits(t, 22, 0);
}
Пример #3
0
void calc_zorder(int size, int *i, int *j, int *level, int levmx, int ibase, int *z_index, int *z_order)
{   unsigned long long ibit,   //   Bitwise representation of x-index.
                       jbit;   //   Bitwise representation of y-index.

   //   Convert the indices to a bitwise representation.
   int ic;
   for (ic = 0; ic < size; ic++)
   {  if (level[ic] < 0) continue;
      ibit = index_to_bit(i[ic], level[ic], levmx, ibase);
      jbit = index_to_bit(j[ic], level[ic], levmx, ibase);
      z_index[ic] = twobit_to_index(ibit, jbit);
      z_order[ic] = ic; }

   //   Sort the z-ordered indices.
   S7_Index_Sort(z_index, size, S7_INT, z_order);

   //   Output ordered mesh information.
   if (DEBUG)
   {   printf("orig index   i     j     lev     ibit       jbit       ijbit      z index  z order\n");
      for (ic=0; ic<size; ic++){
         printf(" %6d   %4d  %4d   %4d   ",ic+1, j[ic], i[ic], level[ic]);
         printbits(index_to_bit(j[ic], level[ic], levmx, ibase));
         printf("   ");
         printbits(index_to_bit(i[ic], level[ic], levmx, ibase));
         printf("   ");
         printbits( index_to_bit(i[ic], level[ic], levmx, ibase)
               | (index_to_bit(j[ic], level[ic], levmx, ibase)
               << 1));
         printf("   %6d     %5d\n",z_index[ic], z_order[ic]); } } }
Пример #4
0
Файл: 2-6.c Проект: eudisd/k-r
int main(void){
    int x = 2, y = 3;
    printbits("x", x);
    printbits("y", y);

    printbits("z", setbits(x, 3, 3, y));
}
Пример #5
0
int main()
{
	char buf[max];
	unsigned int x = 0252;
	int p = 4;
	int n = 3;

	snprintf(buf, max, "%s%d%s%d%s", "invert(x,", p, ",", n, ")");
	printf("%*s --> \n", w1, buf);
	printf("%*s --> %*o\n", w1, "x", w2, x);
	printf("%*s --> ", w1, "x");
	printbits(x);
	invert(x, p, n);

	x = 0252;
	p = 0;
	n = 1;
	snprintf(buf, max, "%s%d%s%d%s", "invert(x,", p, ",", n, ")");
	printf("%*s --> \n", w1, buf);
	printf("%*s --> %*o\n", w1, "x", w2, x);
	printf("%*s --> ", w1, "x");
	printbits(x);
	invert(x, p, n);

	x = 031234567252;
	p = 31;
	n = 1;
	snprintf(buf, max, "%s%d%s%d%s", "invert(x,", p, ",", n, ")");
	printf("%*s --> \n", w1, buf);
	printf("%*s --> %*o\n", w1, "x", w2, x);
	printf("%*s --> ", w1, "x");
	printbits(x);
	invert(x, p, n);
}
Пример #6
0
Файл: gethdr.c Проект: pierz/vic
int getheader ()
{
  unsigned int code, gob;

  /* look for startcode */
  startcode ();
  code = getbits (PSC_LENGTH);
  gob = getbits (5);
  if (gob == SE_CODE)
    return 0;
  if (gob == 0)
  {
    if (trace)
    {

      fprintf (trace_file, "\nPSC: ");
      printbits ((code << (5 + gob)), 22, 22);
    }
    getpicturehdr ();
    if (syntax_arith_coding)    /* reset decoder after receiving */
      decoder_reset ();         /* fixed length PSC string */
  } 
  else
  {
    if (trace)
    {

      fprintf (trace_file, "\nGBSC: ");
      printbits ((code << (5 + gob)), 22, 22);
    }
  }
  return gob + 1;
}
Пример #7
0
int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    printf("usage: %s x y\n", argv[0]);
    return 0;
  }

  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  printf("x = 0x%08x  %s\n", x, printbits(x, 0));
  printf("y = 0x%08x  %s\n", y, printbits(y, 0));

  int z = x&y;
  printf("x & y = 0x%x & 0x%x = %s (0x%x)\n", x, y, printbits(z,0), z);
  z = x|y;
  printf("x | y = 0x%x & 0x%x = %s (0x%x)\n", x, y, printbits(z,0), z);
  z = x^y;
  printf("x ^ y = 0x%x & 0x%x = %s (0x%x)\n", x, y, printbits(z,0), z);
  z = x^x;
  printf("x ^ x = 0x%x\n", z);

  z = ~x;
  printf("~x = 0x%x = %s\n", z, printbits(z,0));
  z = ~y;
  printf("~y = 0x%x = %s\n", z, printbits(z,0));
  x |= 0x20;
  printf("set 6'th bit for x |= 0x20 = 0x%x, %s\n", x, printbits(x,0));
  x &= ~0x20;
  printf("del 6'th bit for x &= ^0x20 = 0x%x, %s\n", x, printbits(x,0));

  return 0;
}
Пример #8
0
void printbits(int length, int number, long long index)
{
    if (length == 0)
        return ;
    long long count;
    count = str[length-1][number];
    
    if (count <= index) {
        fprintf(fout, "1");
        printbits(length-1, number-1, index-count);
    }else {
        fprintf(fout, "0");
        printbits(length-1, number, index);
    }
}
Пример #9
0
// Display thte reset reason
void display_reset_reason(void) {
  dprintf("Reset Flag:");
#ifdef DEBUG
  printbits(RCC_CSR, 32);
#endif  /* DEBUG */
  dprintf("\n");
  dprintf("Reset due to: \n");
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_LPWRRSTF)) {
    dprintf("---> RCC_CSR_LPWRRSTF -- Low Power Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_WWDGRSTF)) {
    dprintf("---> RCC_CSR_WWDGRSTF -- Windowed Watchdog Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_IWDGRSTF)) {
    dprintf("---> RCC_CSR_IWDGRSTF -- Independent Watchdog Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_SFTRSTF)) {
    dprintf("---> RCC_CSR_SFTRSTF -- Software Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_PORRSTF)) {
    dprintf("---> RCC_CSR_PORRSTF -- POR/PDR Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_PINRSTF)) {
    dprintf("---> RCC_CSR_PINRSTF -- NRST PIN Reset Flag\n");
  }
  if (CHECK_BITMASK(RCC_CSR, RCC_CSR_BORRSTF)) {
    dprintf("---> RCC_CSR_BORRSTF -- Brown Out Reset Flag\n");
  }
}
Пример #10
0
/*
 * The main method.
 */
int main(int argc, char *argv[]){
	if (argc==1){
		printf("Error: No input file specified.\n");
		printf("Usage: argv[0] input_file [output_file]\n");
		printf("If no output file is specified, the program will print to standard output.\n");
		exit(3);
	}
	FILE* f = fopen(argv[1], "r");
	if (f == NULL) {
    	perror("In encode, error");
    	exit(3);
    }
	huffmantree* tree=frequency_tree(f);
	char* tree_string=huffmantree_tostring(tree);
	printf("treestring %s\n", tree_string);
	rewind(f);
	FILE* out=stdout;
	if (argc>2){
		out=fopen(argv[2], "w");
	}
	printbits(tree,f,out);
	huffmantree_free(tree);
	fclose(f);
	if(out!=stdout)fclose(out);
	exit(0);
}
Пример #11
0
int getTMNMV ()
{
    int code;

    if (trace)
        fprintf (trace_file, "motion_code (");

    if (getbits1 ())
    {
        if (trace)
            fprintf (trace_file, "1): 0\n");
        return 0;
    }
    if ((code = showbits (12)) >= 512)
    {
        code = (code >> 8) - 2;
        flushbits (TMNMVtab0[code].len);

        if (trace)
        {
            fprintf (trace_file, "0");
            printbits (code + 2, 4, TMNMVtab0[code].len);
            fprintf (trace_file, "): %d\n", TMNMVtab0[code].val);
        }
        return TMNMVtab0[code].val;
    }
Пример #12
0
/* Initilizes randomly all p memories in XI[p][n] matrix
 *
 * PRE: XI != NULL
 *	XI is a [p][n] matrix (ie: holding 'p' memories of 'n' components each)
 */
void
init_XI (unsigned long *XI, unsigned int p, unsigned int n)
{
	int i = 0;
	
	assert (XI != NULL);
	
	/* NOTE With #pragma statement this section becomes non-deterministic,
	 * as the output memory XI[i] will depend on the execution order of the
	 * execution threads, which itself is non-deterministic.
	 *	To regain determinism in the creation of the XI matrix simply
	 * comment the #pragma statement
	 * WARNING mzran13 is NOT threadsafe
	 */
/*	#pragma omp parallel for shared(XI)
*/	for (i=0 ; i<p*n ; i++) {
		XI[i] = (unsigned long) mzran13();
	}
	
	debug ("%s","\nXI reinitialized:\n");
	dfor(i=0 ; i<p*n ; i++) {
		debug ("XI[%d][%d] ", i/n, i%n);
		printbits(XI[i]);
	}
	debug ("%s","\n");
	
	return;
}
Пример #13
0
mmio_window_t mmio_window_new( const gchar *title )
{
    mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );

    int i, j;
    GtkCList *all_list;
    GtkWidget *vbox1;
    GtkWidget *hbuttonbox1;
    GtkWidget *mmr_close;

    mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (mmio->window), title);
    gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);

    vbox1 = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);

    mmio->notebook = gtk_notebook_new ();
    gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);

    hbuttonbox1 = gtk_hbutton_box_new ();
    gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
    gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);

    mmr_close = gtk_button_new_with_mnemonic (_("Close"));
    gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
    GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);

    /* Add the mmio register data */
    all_list = mmio_window_add_page( mmio, "All", NULL );
    for( i=0; i < num_io_rgns; i++ ) {
        GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
            int sz = io_rgn[i]->ports[j].width;
            char addr[10], data[10], bits[40];
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
                    io_rgn[i]->ports[j].desc };
            sprintf( addr, "%08X",
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
            printhex( data, sz, *io_rgn[i]->ports[j].val );
            printbits( bits, io_rgn[i]->ports[j].width,
                       *io_rgn[i]->ports[j].val );
            gtk_clist_append( list, arr );
            gtk_clist_append( all_list, arr );
        }
    }

    g_signal_connect ((gpointer) mmio->window, "delete_event",
                      G_CALLBACK (on_mmio_delete_event),
                      NULL);
    g_signal_connect ((gpointer) mmr_close, "clicked",
                      G_CALLBACK (on_mmio_close_clicked),
                      mmio);

    gtk_widget_show_all( mmio->window );
    return mmio;
}
Пример #14
0
int main(int argc, char *argv[])
{
	int x = atoi(argv[1]);
	int p = atoi(argv[2]);
	int n = atoi(argv[3]);
	int temp1 = ~0 << n;
	int temp2 = temp1 << (p+1-n);
	int temp3 = ~ temp2;
	printf("x = ");
	printbits(x);
	printf("temp1= ");
	printbits(temp1);
	printf("temp2= ");
	printbits(temp2);
	printf("temp3= ");
	printbits(temp3);
	int temp4 = x ^ temp3;
	printf("temp4= ");
	printbits(temp4);
	return 0;
}
Пример #15
0
uint8_t* setdiff(uint8_t* x,uint8_t *y,int nrow)//x-y
  { int i=0;
    uint8_t* ret=(uint8_t*)R_alloc(nrow , sizeof(uint8_t));
    for(i=0;i<nrow;i++)
      {
        uint8_t tmp=(~y[i]);
        
        Rprintf("x[%i]=",i);
        printbits(x[i]);
        Rprintf("\n");
        Rprintf("y[%i]=",i);
        printbits(y[i]);
        Rprintf("\n");
        Rprintf("tmp=\n");
        printbits(tmp);
        Rprintf("\n");

        ret[i]=(x[i]&tmp);
      }
    return ret;
  }
Пример #16
0
int main(int argc, char* argv[]){
  float f;
  unsigned int i;
  
  if (argc < 2) {
    printf("Too few arguments");
    return EXIT_FAILURE;
  }

  f = atof(argv[1]);
  i = ftoi(f);
  printbits(i, SBITS, EBITS-1);
  printf(" ");
  printbits(i, EBITS, MBITS-1);
  printf(" ");
  printbits(i, MBITS, sizeof(f)*8-1);
  printf("\n");


  return EXIT_SUCCESS;
}
Пример #17
0
Файл: 01.c Проект: 2ion/scripts
int main(int argc, char**argv) {
  long int x;
  int fd;
  size_t cnt;
  unsigned char _buf[BUILTIN_BUF_LEN] = {0};
  unsigned char *buf = _buf;

  if(argc != 2)
    return 1;

  switch(x = strtol((const char*)argv[1], NULL, 0xA)) {
    case LONG_MIN:
    case LONG_MAX:
      perror("Invalid argument");
      return 1;
    default:
      break;
  }

  cnt = (size_t) (x < 0 ? 0 : x);

  if(cnt > BUILTIN_BUF_LEN) {
    if((buf = malloc(sizeof(char)*cnt)) == NULL) {
      perror("Memory allocation error");
      return 1;
    }
    memset(buf, 0, cnt);
  }

  if((fd = open("/dev/urandom", O_RDONLY)) == -1) {
    perror("Failed to open /dev/urandom");
    FREEBUF(buf, _buf);  
    return 1;
  }

  if(read(fd, buf, cnt) == -1) {
    perror("Couldn't read from /dev/urandom");
    close(fd);
    FREEBUF(buf, _buf);
    return 1;
  }

  for(x = 0; x < cnt; x++)
    printbits(buf[x]);

  putchar('\n');

  close(fd);
  FREEBUF(buf, _buf);

  return 0;
}
Пример #18
0
void print_tree(NODE *node, unsigned int pos, unsigned int depth){
	//puts("printing tree structure:");
	//puts("1 is a left turn, 0 is a right turn, root starts at 0");
	printf("pos, depth(%d): ", depth);
	printbits(pos, depth-1);
	printf("\t{%G, %G, %G}\t%u\n", node->val[0], node->val[1], node->val[2], node);

	if(node->left != NULL){
		pos = pos << 1;
		pos++;
		print_tree(node->left, pos, depth+1);
		pos--;
		pos = pos >> 1;
	}
Пример #19
0
int main()
{
    FILE *fin = fopen("kimbits.in", "r");
    fout = fopen("kimbits.out", "w");
    int length, number, i;
    long long index;
    fscanf(fin, "%d %d %lld\n", &length, &number, &index);
    
    initStr();
    //for (i = 1; i <= 19; i++) {
    printbits(length, number, index-1);
    fprintf(fout, "\n");
    //}
    
    fclose(fin);
    fclose(fout);
}
Пример #20
0
/* Function
 *
 *    Return x with the n bits that begin at position p inverted
 *    
 * 
 */
unsigned int invert(unsigned int x, int p, int n)
{
	/* examples in comments show low order 8 bits
	 *    p = 4
	 *    n = 3  
	 *    x = 1010 1010 
	 */
	unsigned int mh = ~0 << (p + 1);           /* mask high eg 1110 0000 */

        /*  the following cludge was required because shifting 1000 by
	 *  1 to the left resulted in 1111 instead of 0000 as expected
	 *  (probably due to rounding up in order to try and represent
	 *  a number outside the range of the word size)
	 */
	if (p == ((sizeof(x) * CHAR_BIT) - 1))
		mh = 0;
	printf("%*s --> ", w1, "mh");
	printbits(mh);

	unsigned int ml = ~(~0 << (p + 1 - n));    /* mask low eg 0000 0011 */
	printf("%*s --> ", w1, "ml");
	printbits(ml);

	unsigned int ma = mh | ml;                 /* mask and eg 1110 0011 */
	printf("%*s --> ", w1, "ma");
	printbits(ma);

	unsigned int x0 = x & ma;                  /* x0 is    eg 1010 0010 */
	printf("%*s --> ", w1, "x0");
	printbits(x0);

	unsigned int xa = x & ~ma;                 /* xa is    eg 0000 1000 */
	printf("%*s --> ", w1, "xa");
	printbits(xa);

	unsigned int xc = ~xa & ~ma;               /* xc is    eg 0001 0100 */
	printf("%*s --> ", w1, "xc");
	printbits(xc);

	unsigned int re = xc | x0;                 /* return   eg 1011 0110 */
	printf("%*s --> ", w1, "re");
	printbits(re);
	printf("%*s --> %*o\n", w1, "re", w2, re);

	return re;
}
Пример #21
0
void mmio_window_update( mmio_window_t mmio )
{
    int i,j, count = 0;
    GtkCList *page, *all_page;
    char data[10], bits[40];

    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));

    for( i=0; i < num_io_rgns; i++ ) {
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
                io_rgn[i]->id ));
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
            if( *io_rgn[i]->ports[j].val !=
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
                int sz = io_rgn[i]->ports[j].width;
                /* Changed */
                printhex( data, sz, *io_rgn[i]->ports[j].val );
                printbits( bits, sz, *io_rgn[i]->ports[j].val );

                gtk_clist_set_text( page, j, 2, data );
                gtk_clist_set_text( page, j, 3, bits );
                gtk_clist_set_foreground( page, j, &gui_colour_changed );

                gtk_clist_set_text( all_page, count, 2, data );
                gtk_clist_set_text( all_page, count, 3, bits );
                gtk_clist_set_foreground( all_page, count, &gui_colour_changed );

            } else {
                gtk_clist_set_foreground( page, j, &gui_colour_normal );
                gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
            }
            count++;
        }
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, LXDREAM_PAGE_SIZE );
    }
}
Пример #22
0
void treePop(int* splits, double* w,int* ncolp,int* np, int* ed1, int* ed2, double* edLen)
  {
    int n=*np;
    int ncol=*ncolp;
    int nrow=ceil(n/(double)8);
    uint8_t split[nrow][ncol];
    int i=0,j=0;

    /*Rprintf("n=%i nrow=%i ncol=%i\n",n,nrow,ncol);
    Rprintf("got\n");
    for(i=0;i<ncol;i++)
    {
     for(j=0;j<nrow;j++)
       {
          Rprintf("%i ",splits[i*nrow+j]);
       }
     Rprintf("\n");
    }*/
    
    for(i=0;i<ncol;i++)
    {
     for(j=0;j<nrow;j++)
       { 
         split[j][i]=(uint8_t)splits[i*nrow+j];
       }
    }
    /*Rprintf("short-ed\n");
    for(i=0;i<nrow;i++)
    {
      for(j=0;j<ncol;j++)
       {
         printbits(split[i][j]);
         Rprintf("\n");
       }
      Rprintf("\n");
    }*/
    

   uint8_t vlabs[2*n-1][nrow];
   for(i=0;i<nrow-1;i++)
    {
       vlabs[n+1][i]=255;
    }
   vlabs[n+1][nrow-1]=~((uint8_t)(pow(2,8-(n%8))-1));

   int bitt_count[ncol];
   uint8_t msk=~((uint8_t)(pow(2,8-(n%8))-1));//mask out trailing bits
   printbits(msk);
   for(i=0;i<ncol;i++)
    {
      int sum=0;
      for(j=0;j<nrow-1;j++)
       { //Rprintf("countbits(%i)=%i ",split[j][i],count_bits(split[j][i]));
         sum+=count_bits(split[j][i]);
       }
      uint8_t bt=split[nrow-1][i];
      bt&=msk;
      //Rprintf("countbits(%i)=%i ",bt,count_bits(bt));
      sum+=count_bits(bt);
     // Rprintf("bit_count[%i]=%i ",i,sum);
      //Rprintf("\n");
      if(sum>n/2)
       {
         for(j=0;j<nrow;j++)
          {
             split[j][i]=~split[j][i];
          }
         split[nrow-1][i]&=msk;
         sum=n-sum;
       }
      bitt_count[i]=sum;
    }
   int ind[ncol];
   for(i=0;i<ncol;i++)
     {
       ind[i]=i;
     }

   for(i=0;i<ncol-1;i++)
     {
       for(j=i+1;j<ncol;j++)
        {
          if(bitt_count[i]<bitt_count[j])
            { int aux;
              aux=bitt_count[i];
              bitt_count[i]=bitt_count[j];
              bitt_count[j]=aux;
              aux=ind[i];
              ind[i]=ind[j];
              ind[j]=aux;
            }
        }
     }
   int nNodes=n+1;
   int numEdges=0;
   for(i=0;i<ncol;i++)
    {  int ii=0;
       //Rprintf("split %i\n",i);
       uint8_t sp[nrow];
       for(ii=0;ii<nrow;ii++)
         {//copy split into sp
          sp[ii]=split[ii][ind[i]];
         }
      //search for node whose labellings are a superset of the current split
      for(j=n+1;j<=nNodes;j++)
       {
          uint8_t vl[nrow];
          for(ii=0;ii<nrow;ii++)
            {//copy vertex labeling into vl
              vl[ii]=vlabs[j][ii];
            }
         int sw=0;//print current split
         for(ii=0;ii<nrow;ii++)
           {
             //Rprintf("sp[%i]= ",ii);
            //printbits(sp[ii]);
           }
         //Rprintf("\n");//print current label
         for(ii=0;ii<nrow;ii++)
           {
            // Rprintf("vl[%i]= ",ii);
           //  printbits(vl[ii]);
           }
         //Rprintf("\n");
         uint8_t* sd=setdiff(sp,vl,nrow);
         //print the setdifference
         for(ii=0;ii<nrow/*-1*/;ii++)
           { //Rprintf("sd[%i]=%i ",ii,sd[ii]);
             if(sd[ii]!=0)sw=1;
           }
        // Rprintf("\n");
         
         sd[nrow-1]&=msk;
         //Rprintf("sd[%i]=%i ",nrow-1,sd[nrow-1]);
         if(sd[nrow-1]!=0)sw=1;
         if(sw==0)//setdiff==0, so we split vertex j
          { // Rprintf("vertex %i",j);
             ed1[numEdges]=j;
             
             int gn=-1;
            // Rprintf("bitt_count[%i]=%i\n",i,bitt_count[i]);
             if(bitt_count[i]>=2)//if not trivial split
             {nNodes++;
              gn=nNodes;
             }
             else
             {
               gn=lsb(sp);
             }
            // Rprintf("gn=%i\n",gn);
             ed2[numEdges]=gn;
             edLen[numEdges]=w[ind[i]];
             numEdges++;
             uint8_t* sdd=setdiff(vl,sp,nrow);
             for(ii=0;ii<nrow;ii++)//label current vertex byset difference
                                   //and new vertex by actual split
               {
                 vlabs[j][ii]=sdd[ii];
                 vlabs[gn][ii]=sp[ii];
               }
             //print new labels
            // Rprintf("new v\n");
             int jj=0;
             for(ii=1;ii<=nNodes;ii++)
              {//Rprintf("node %i : ",ii);
               for(jj=0;jj<nrow;jj++)
                {
                  //printbits(vlabs[ii][jj]);
                 // Rprintf(" ");
                }
              // Rprintf("\n");
              }
             break;
          }

       }
    }
  }
Пример #23
0
Файл: gethdr.c Проект: pierz/vic
static void getpicturehdr ()
{
  int pos, pei, tmp;
  int UFEP = 0;
  int BCI = 0;
  int clock_conversion_code = 0;
  int clock_divisor = 0;
  int extended_temporal_reference = 0;
  int prev_plus_P_temp_ref = 0;

  pos = ld->bitcnt;

  prev_plus_P_temp_ref = temp_ref;
  temp_ref = getbits (8);
  if (trace)
  {
    fprintf (trace_file, "\nTR: ");
    printbits (temp_ref, 8, 8);
  }
  if (trd < 0)
    trd += 256;

  tmp = getbits (1);            /* always "1" */
  if (trace)
    fprintf (trace_file, "\nSpare: %d", tmp);
  if (!tmp)
    if (!quiet)
      printf ("warning: spare in picture header should be \"1\"\n");
  tmp = getbits (1);            /* always "0" */
  if (trace)
    fprintf (trace_file, "\nH.261 distinction bit: %d", tmp);
  if (tmp)
    if (!quiet)
      printf ("warning: H.261 distinction bit should be \"0\"\n");
  tmp = getbits (1);            /* split_screen_indicator */
  if (trace)
    fprintf (trace_file, "\nsplit_screen_indicator: %d", tmp);
  if (tmp)
  {
    if (!quiet)
      printf ("error: split-screen not supported in this version\n");
    exit (-1);
  }
  tmp = getbits (1);            /* document_camera_indicator */
  if (trace)
    fprintf (trace_file, "\ndocument_camera_indicator: %d", tmp);
  if (tmp)
    if (!quiet)
      printf ("warning: document camera indicator not supported in this version\n");

  tmp = getbits (1);            /* freeze_picture_release */
  if (trace)
    fprintf (trace_file, "\nfreeze_picture_release: %d", tmp);
  if (tmp)
    if (!quiet)
      printf ("warning: frozen picture not supported in this version\n");
  tmp = getbits (3);
  if (trace)
  {
    fprintf (trace_file, "\nsource_format: ");
    printbits (tmp, 3, 3);
  }

  if (tmp == EXTENDED_PTYPE)
  {
    if (trace)
      fprintf (trace_file, "\n----------EXTENDED_PTYPE----------");
    plus_type = 1;
    UFEP = getbits (3);
    if (trace)
    {
      fprintf (trace_file, "\nUFEP: ");
      printbits (UFEP, 3, 3);
    }
    if (UFEP == 1)
    {                           /* OPPTYPE */
      if (trace)
        fprintf (trace_file, "\n----------OPTIONAL PLUS PTYPE----------");
      source_format_old = source_format;
      source_format = getbits (3);
      if (trace)
      {
        fprintf (trace_file, "\nsource_format: ");
        printbits (source_format, 3, 3);
      }
    
      /* optional custom picture clock frequency */
      optional_custom_PCF = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\noptional_custom_PCF: ");
        printbits (optional_custom_PCF, 1, 1);
      }
      if (optional_custom_PCF)
      {
        if (!quiet)
          printf ("error: Optional custom picture clock frequency is not supported in this version\n");
        exit (-1);
      }
      mv_outside_frame = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nmv_outside_frame: ");
        printbits (mv_outside_frame, 1, 1);
      }
      long_vectors = (mv_outside_frame ? 1 : 0);
      syntax_arith_coding = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nsyntax_arith_coding: ");
        printbits (syntax_arith_coding, 1, 1);
      }
      adv_pred_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nadv_pred_mode: ");
        printbits (adv_pred_mode, 1, 1);
      }
      mv_outside_frame = (adv_pred_mode ? 1 : mv_outside_frame);
      overlapping_MC = (adv_pred_mode ? 1 : 0);
      use_4mv = (adv_pred_mode ? 1 : 0);
      pb_frame = 0;
      advanced_intra_coding = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nadvanced_intra_coding: ");
        printbits (advanced_intra_coding, 1, 1);
      }
      deblocking_filter_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\ndeblocking_filter_mode: ");
        printbits (deblocking_filter_mode, 1, 1);
      }
      mv_outside_frame = (deblocking_filter_mode ? 1 : mv_outside_frame);
      use_4mv = (deblocking_filter_mode ? 1 : use_4mv);

      slice_structured_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nslice_structured_mode: ");
        printbits (slice_structured_mode, 1, 1);
      }
      if (slice_structured_mode)
      {
        if (!quiet)
          printf ("error: Slice structured mode is not supported in this version\n");
        exit (-1);
      }
      reference_picture_selection_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nreference_picture_selection_mode: ");
        printbits (reference_picture_selection_mode, 1, 1);
      }
#if 0
      if (reference_picture_selection_mode)
      {
        if (!quiet)
          printf ("error: Reference picture selection mode is not supported in this version\n");
        exit (-1);
      }
#endif
      independently_segmented_decoding_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nindependently_segmented_decoding_mode: ");
        printbits (independently_segmented_decoding_mode, 1, 1);
      }
      if (independently_segmented_decoding_mode)
      {
        if (!quiet)
          printf ("error: Independently segmented decoding mode is not supported in this version\n");
        exit (-1);
      }
      alternative_inter_VLC_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nalternative_inter_VLC_mode: ");
        printbits (alternative_inter_VLC_mode, 1, 1);
      }
      modified_quantization_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nmodified_quantization_mode: ");
        printbits (modified_quantization_mode, 1, 1);
      }
      tmp = getbits (4);
      if (trace)
      {
        fprintf (trace_file, "\nspare, reserve, reserve, reserve: ");
        printbits (tmp, 4, 4);
      }
      if (tmp != 8)
      {                         /* OPPTYPE : bit15=1, bit16,bit17,bit18=0 */
        if (!quiet)
          printf ("error: The last 4 bits of OPPTYPE is expected to be 1000\n");
        exit (-1);
      }
    }
    if ((UFEP == 1) || (UFEP == 0))
    {
      if (UFEP == 0)
      {
        if (scalability_mode >= 3)
        {
          horizontal_size = lines[base_source_format];
          vertical_size = pels[base_source_format];

          mb_width = horizontal_size / 16;
          mb_height = vertical_size / 16;

          /* Need to store previous (reference layer) values 
           * for interpolation purposes, as the new values, 
           * i.e. of the spatially scaled layer, depend on 
           * the type of spatial scalability in use. */
          ref_coded_picture_width = coded_picture_width = horizontal_size;
          ref_coded_picture_height = coded_picture_height = vertical_size;
          ref_chrom_width = chrom_width = coded_picture_width >> 1;
          ref_chrom_height = chrom_height = coded_picture_height >> 1;

          source_format = base_source_format;
        }
      }

      /* MMPTYPE */
      if (trace)
        fprintf (trace_file, "\n----------MANDATORY PLUS PTYPE----------");
      pict_type = getbits (3);
      if (trace)
      {
        fprintf (trace_file, "\npict_type: ");
        printbits (pict_type, 3, 3);
      }
      if (pict_type == PCT_IPB)
        pb_frame = IM_PB_FRAMES;
      else
        pb_frame = 0;

      if (PCT_B == pict_type)
      {
        true_B_frame = ON;
        /* Allow motion over picture boundaries, regardless of whether or
         * not UMV is turned on. */
        mv_outside_frame = 1;
        true_b_trb = temp_ref - prev_non_disposable_temp_ref;
      } else
      {
        true_B_frame = OFF;
        prev_non_disposable_temp_ref = next_non_disposable_temp_ref;
        next_non_disposable_temp_ref = temp_ref;
        trd = temp_ref - prev_non_disposable_temp_ref;
      }

      reference_picture_resampling_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nreference_picture_resampling_mode: ");
        printbits (reference_picture_resampling_mode, 1, 1);
      }
      if (reference_picture_resampling_mode)
      {
        if (!quiet)
          printf ("error: Reference picture resampling mode is not supported in this version\n");
        exit (-1);
      }
      reduced_resolution_update_mode = getbits (1);
      if (trace)
      {
        fprintf (trace_file, "\nreduced_resolution_update_mode: ");
        printbits (reduced_resolution_update_mode, 1, 1);
      }
      if (reduced_resolution_update_mode)
      {
        if (!quiet)
          printf ("error: Reduced resolution update mode is not supported in this version\n");
        exit (-1);
      }
      rtype = getbits (1);      /* rounding type */
      if (trace)
      {
        fprintf (trace_file, "\nrounding_type: ");
        printbits (rtype, 1, 1);
      }
      if (trace)
      {
        fprintf (trace_file, "\nrtype: ");
        printbits (rtype, 1, 1);
      }
      tmp = getbits (3);
      if (trace)
      {
        fprintf (trace_file, "\nreserve, reserve, spare: ");
        printbits (tmp, 3, 3);
      }
      if (tmp != 1)
      {                         /* MPPTYPE : bit7,bit8=0  bit9=1 */
        if (!quiet)
          exit (-1);
      }
    } else
    {
      /* UFEP is neither 001 nor 000 */
      if (!quiet)
Пример #24
0
void print8bits(uint8_t n)  {
  printbits(n, 8);
}
Пример #25
0
/* Jumps one time-step ahead in time, for all the neurons in the neural network
 * This is done updating each neuron stored in 'S', and registering in 'm' all
 * the new overlaps between 'S' and each 'XI[mu]'
 *
 * It uses DETERMINISTIC logic
 *
 * PRE: S != NULL
 *	S is an [n] dimensional vector
 *	XI != NULL
 *	XI is a [p][n] matrix (ie: holding 'p' memories of 'n' components each)
 *	m != NULL
 *	m is a [p] dimensional vector
 */
static void
update_deterministic_network (unsigned long *S, unsigned long *XI, long *m,
			      unsigned int n, unsigned int p)
{
	int i = 0, j = 0, mu = 0;
	unsigned long	oldSi = 0,
			mask = 0;
	long	h = 0,
		exced = 0,
		XImui = 0;
	
	assert (S  != NULL);
	assert (XI != NULL);
	assert (m  != NULL);
	
	/* Updating each neuron.
	 * With 'i' we step on a position within S, and with 'j' we access
	 * (one bit at a time) all 'MSB' neurons stored there.
	 * Usually MSB == 64
	 */
	for (i=0 ; i<n ; i++) {
		for (j=LSB ; j<MSB ; j++) {
			
			mask = ((long) 1) << j;
			h = 0;
			
			for (mu=0 ; mu<p ; mu++) {
				XImui = XI[(mu*n)+i] & mask;
				h += norm(XImui) * m[mu];
			}
			oldSi = S[i];
			exced = ((long) p) * norm(S[i]&mask);
			/* NOTE exced = p * S[i] */
			
			debug ("S[%d] before bit %lu flip:\n", i, i*MSB+j);
			dfor(int k=0 ; k<n ; k++)
				printbits(S[k]);
			
			/* If h >= 0 then mask holds the position of the bit  *
			 * we have to set (to 1) in S[i]		      *
			 * Otherwise mask's bitwise negation has a single '0' *
			 * in the exact position of the bit we have to reset  */
			if (h - exced >= 0) {
				S[i] |= mask;
			} else {
				S[i] &= ~mask;
			}
			
			debug ("S[%d] after:\n", i);
			dfor (int k=0 ; k<n ; k++)
				printbits(S[k]);
			debug ("%s","\n");
			
			/* Recalculating overlaps in m (if needed) */
			if (S[i] != oldSi) {
				
				update_overlaps (S, XI, m, n, p);
				
				debug ("\n\t> S[%d]: flip bit %lu\n", i, i*MSB+j);
				dfor(int k=0 ; k<n ; k++) {
					debug ("%s","\t");
					printbits(S[k]);
				}
			}
		}
	}
Пример #26
0
void printhalf(uint16_t t)
{
    printbits(t, 15, 15);
    printf("   "); printbits(t, 14, 10);
    printbits(t, 9, 0);
}
Пример #27
0
void print16bits(uint16_t n) {
  printbits(n, 16);
}
Пример #28
0
void print32bits(uint32_t n) {
  printbits(n, 32);
}