Ejemplo n.º 1
0
int main()
{
    int i=5225,j,k;
    printf("\ndecimal %d is same as binary",i);
    showbits(i);
    
    for(j=0;j<=5;j++)
    {
        k=i>>j;             
     printf("\n%d rightshift %dgives ",i,j);
     showbits(k) ;
     }
    getch();
     }
Ejemplo n.º 2
0
void clearBit(int x, unsigned char position) //function that clears bit with position('position') in variable('x') to 0; 

{
	x &= ~(1u << position);
	printf("\nNew value (clearBit) : %x\n", x);
	showbits(x);
}
Ejemplo n.º 3
0
void getblock (int comp, int mode, int INTRA_AC_DC, int Mode)
{
    int val, i, j, sign;
    unsigned int code;
    VLCtabI *tab;
    short *bp;
    int run, last, level, QP;
    short *qval;


    /* store_code used in alternative inter VLC mode */
    int use_intra = 0;
    CodeCoeff store_code[64];
    int coeff_ind;

    bp = ld->block[comp];

    /* decode AC coefficients (or all coefficients in advanced intra coding
     * mode) */
    if (trace)
        fprintf (trace_file, "block: %i\n", comp);

    if (alternative_inter_VLC_mode && !(Mode == MODE_INTRA || Mode == MODE_INTRA_Q))
    {
        coeff_ind = 0;
        use_intra = 0;
        for (i = (mode == 0);; i++)
        {
            code = showbits (12);
            store_code[coeff_ind].code = code;
            if (code >= 512)
                tab = &DCT3Dtab0[(code >> 5) - 16];
            else if (code >= 128)
                tab = &DCT3Dtab1[(code >> 2) - 32];
            else if (code >= 8)
Ejemplo n.º 4
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;
    }
Ejemplo n.º 5
0
static void showregs(void)
{
	ccprintf("GINTSTS:   0x%08x\n", GR_USB_GINTSTS);
	showbits(GR_USB_GINTSTS);
	ccprintf("GINTMSK:   0x%08x\n", GR_USB_GINTMSK);
	showbits(GR_USB_GINTMSK);
	ccprintf("DAINT:     0x%08x\n", GR_USB_DAINT);
	ccprintf("DAINTMSK:  0x%08x\n", GR_USB_DAINTMSK);
	ccprintf("DOEPMSK:   0x%08x\n", GR_USB_DOEPMSK);
	ccprintf("DIEPMSK:   0x%08x\n", GR_USB_DIEPMSK);
	ccprintf("DCFG:      0x%08x\n", GR_USB_DCFG);
	ccprintf("DOEPCTL0:  0x%08x\n", GR_USB_DOEPCTL(0));
	ccprintf("DIEPCTL0:  0x%08x\n", GR_USB_DIEPCTL(0));
	ccprintf("DOEPCTL1:  0x%08x\n", GR_USB_DOEPCTL(1));
	ccprintf("DIEPCTL1:  0x%08x\n", GR_USB_DIEPCTL(1));
	ccprintf("DOEPCTL2:  0x%08x\n", GR_USB_DOEPCTL(2));
	ccprintf("DIEPCTL2:  0x%08x\n", GR_USB_DIEPCTL(2));
}
Ejemplo n.º 6
0
// max 11bits
static INLINE int getDCdiff(int dct_dc_size, mpeg_decode* dec)
{
	int code = showbits(dec,32); //we need only dct_dc_size bits (but in the higher bits)
	int adj = 0;
	flushbits(dec,dct_dc_size);
	if (code >= 0)
		adj = (-1 << dct_dc_size) + 1;
	return adj + ((uint32_t)code >> (32-dct_dc_size));
}
Ejemplo n.º 7
0
static inline unsigned int getbits32()
{
  unsigned int l;

  l = showbits(32);
  flushbits32();

  return l;
}
Ejemplo n.º 8
0
int main()
{
    int j;
    printf("\ndecimal=0 is same as binary equivalent :0");
    for(j=0;j<5;j++)
    {
     printf("\ndecimal=%d is same as binary equivalent :",j+1);
     showbits(j+1) ;
     }
     getch();
     }
Ejemplo n.º 9
0
static void ext_user_data()
{
  int code,ext_ID;

  startcode();

  while ((code = showbits(32))==EXT_START_CODE || code==USER_START_CODE)
  {
    if (code==EXT_START_CODE)
    {
      flushbits32();
      ext_ID = getbits(4);
      switch (ext_ID)
      {
      case SEQ_ID:
        sequence_extension();
        break;
      case DISP_ID:
        sequence_display_extension();
        break;
      case QUANT_ID:
        quant_matrix_extension();
        break;
      case SEQSCAL_ID:
        sequence_scalable_extension();
        break;
      case PANSCAN_ID:
        picture_display_extension();
        break;
      case CODING_ID:
        picture_coding_extension();
        break;
      case SPATSCAL_ID:
        picture_spatial_scalable_extension();
        break;
      case TEMPSCAL_ID:
        picture_temporal_scalable_extension();
        break;
      default:
        fprintf(stderr,"reserved extension start code ID %d\n",ext_ID);
        break;
      }
      startcode();
    }
    else
    {
      if (verbose)
        printf("user data\n");
      flushbits32();
      startcode();
    }
  }
}
Ejemplo n.º 10
0
int main() 
{
  int j;
  
  for(j = 0; j <= 5; j++)
  {
    printf("Decimal %d is same as binary", j);
    
    showbits (j);
   }
   
    return 0;
}
Ejemplo n.º 11
0
// Copyright 1997-1999 J.M.Pullen/George Mason University
// Interface for CRC generator for Network Workbench
//*********************************************************************
FCS stack::generate_FCS(bit_frame* FCS_frame)
                                  // creates crc for bit frame
                                  // using CCITT 0-5-12-16 polynomial
{
	// NOTE:  throughout this program position 0 is treated as high-order
	// in character and bit strings for parity computation, etc.

	// Create an FCS array with 16 bits
	FCS result_FCS = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

	// Calculate the length of the incoming data frame
	int input_length = 8*bittobyte(8,FCS_frame->frame_bits);

	// Initialize a feedback bit
	int feedback = 0;

	// For every bit in the data frame, going left to right and
	// ignoring the framing flags
	for(int input_pos = 8; input_pos < input_length-8; input_pos++) {
		// Push the high-order FCS bit (bit 0) into the feedback bit
		feedback = result_FCS.FCS_bits[0];

		// Now shift every bit in the FCS array left one position
		for (int shift_pos = 0; shift_pos < 15; shift_pos++) {

			// If we're shifting something into bits 5 or 12 of
			// the CCITT standard (which are bits 10 and 3 for us),
			// XOR the shifted bit before storing it
			if (shift_pos == 10 || shift_pos == 3) {
				result_FCS.FCS_bits[shift_pos] = feedback ^ result_FCS.FCS_bits[shift_pos+1];
			
			// Otherwise, just shift left
			} else {
				result_FCS.FCS_bits[shift_pos] = result_FCS.FCS_bits[shift_pos+1];
			}
		}

		// Now XOR the incoming data bit with the feedback bit
		// and put it into the lowest-order bit of FCS
		result_FCS.FCS_bits[15] = feedback ^ FCS_frame->frame_bits[input_pos];
	}

	// Print the resulting FCS array
	cout << "result_FCS: ";
	showbits(result_FCS.FCS_bits, 16);
	cout << endl;

	return result_FCS;
}
Ejemplo n.º 12
0
inline int getidctblock(long *bp, int comp, int *dctpred, const long *qmatrix, int qscale)
{
    int i, code, size, val;
    char *tab;

    comp=(comp<4)?0:(comp-3);

    for (i=0; i<64; i++)
        bp[i]=0;

    code=showbits(10);
    if (!comp)
    {
        if (code>=992)
            tab=DClumtab1[(code>>1)-496];
        else
            tab=DClumtab0[code>>5];
    }
Ejemplo n.º 13
0
// max 10 bits
static INLINE int getDCsizeChr( mpeg_decode* dec )
{
	int i,code;
	
	if (!getbits1(dec))
		return getbits(dec,1);
	
	code = showbits(dec,9);

	for (i=1;i<10;i++,code<<=1)
		if (!(code & 256))
		{
			flushbits(dec,i);
			return i+1;
		}

	flushbits(dec,9);
	return 11;
}
Ejemplo n.º 14
0
void bit_out_psc_layer()
{
  if (showbits(17)!=1) { /* check for startcode in Arithmetic Decoder FIFO */

    bit = getbits(1);

    if(zerorun > 13) {	/* if number of consecutive zeros = 14 */	 
      if (!bit) {
        if (trace)
          fputs("PSC/GBSC, Header Data, or Encoded Stream Error \n",dlog);
        zerorun = 1;        
      }
      else { /* if there is a 'stuffing bit present */
        if (trace)
          fputs("Removing Startcode Emulation Prevention bit \n",dlog);
        bit = getbits(1);        /* overwrite the last bit */	
        zerorun = !bit;        /* zerorun=1 if bit is a '0' */
      }
    }

    else { /* if consecutive zero's not exceeded 14 */

      if (!bit)
        zerorun++;
      else
        zerorun = 0;
    }

  } /* end of if !(showbits(17)) */

  else {
    bit = 0;
    if (trace)
      fputs("Startcode Found:Finishing Arithmetic Decoding using 'Garbage bits'\n",dlog);
  }

   /*	
   printf("lastbit = %ld bit = %ld zerorun = %ld \n", lastbit, bit, zerorun); 
   lastbit = bit;
   */
        /* latent diagnostics */
        
}
Ejemplo n.º 15
0
void getblock(int comp,int mode)
{
  int val, i, j, sign;
  unsigned int code;
  VLCtabI *tab;
  short *bp;
  int run, last, level, QP;
  short *qval;

  bp = ld->block[comp];   

  /* decode AC coefficients */
  for (i=(mode==0); ; i++) {
    code = showbits(12);
    if (code>=512)
      tab = &DCT3Dtab0[(code>>5)-16];
    else if (code>=128)
      tab = &DCT3Dtab1[(code>>2)-32];
    else if (code>=8)
Ejemplo n.º 16
0
event_t vld_intra_dct() 
{
	event_t event;
	tab_type *tab = NULL;
	int lmax, rmax;

	tab = vldTableB16(showbits(12));
	if (!tab) { /* bad code */
		event.run   = 
		event.level = 
		event.last  = -1;
		return event;
	} 

	if (tab->val != ESCAPE) {
		event.run   = (tab->val >>  6) & 63;
		event.level =  tab->val        & 63;
		event.last  = (tab->val >> 12) &  1;
		event.level = getbits(1) ? -event.level : event.level;
	} else {
Ejemplo n.º 17
0
void bit_out_psc_layer ()
{
  if (showbits (17) != 1)
  {                             /* check for startcode in Arithmetic
                                 * Decoder FIFO */

    bit = getbits (1);

    if (zerorun > 13)
    {                           /* if number of consecutive zeros = 14 */
      if (!bit)
      {
        zerorun = 1;
      } else
      {                         /* if there is a 'stuffing bit present */
        bit = getbits (1);      /* overwrite the last bit */
        zerorun = !bit;         /* zerorun=1 if bit is a '0' */
      }
    } else
    {                           /* if consecutive zero's not exceeded 14 */

      if (!bit)
        zerorun++;
      else
        zerorun = 0;
    }

  }
   /* end of if !(showbits(17)) */ 
  else
  {
    bit = 0;
  }

  /* diag_printf("lastbit = %ld bit = %ld zerorun = %ld \n", lastbit, bit,
   * zerorun); lastbit = bit; */
  /* latent diagnostics */

}
Ejemplo n.º 18
0
// max 9 bits
static INLINE int getDCsizeLum( mpeg_decode* dec )
{
	int i,code;
	
	if (!getbits1(dec))
		return getbits(dec,1)+1;

	if (!getbits1(dec))
		return getbits(dec,1)*3;
	
	code = showbits(dec,7);

	for (i=1;i<8;i++,code<<=1)
		if (!(code & 64))
		{
			flushbits(dec,i);
			return i+3;
		}

	flushbits(dec,7);
	return 11;
}
Ejemplo n.º 19
0
static int showbitslarge( mpeg_decode* dec, int n )
{
	int i = showbits(dec,n);
	i |= *dec->bitptr >> (40-n-dec->bitpos);
	return i;
}
Ejemplo n.º 20
0
Archivo: gethdr.c Proyecto: pierz/vic
void startcode ()
{
  /* search for new picture start code */
  while (showbits (PSC_LENGTH) != 1l)
    flushbits (1);
}
int main(void)
{
  int i, strt,  sector,k,j,p,q=0;
  char buf[512],ch_out;
  clrscr();
  printf("Insert a diskette into drive A and press any key\n");
  getch();
 printf("sec  ");
 scanf("%d",&p);

  for(k=p;k<=p;k++)
  {
  sector = k;
  if (absread(0, 1, sector, &buf) != 0)
  {
     perror("Disk problem");
     exit(1);
  }
  printf("Read OK\n");
  strt = 0;
  for(j=1;j<=15;j++,q+=32)
  {
  //if(j==1)
  //{
  for (i=q; i<q+32; i++)
  {
    if(i%32==0)
 printf("\n-------------------------------------------------\n");
 if(i==(q+8)||i==(q+11)||i==(q+12)||i==(q+22)||i==(q+24)||i==(q+26)||i==(q+28))
 printf("\n\n");
     ch_out = buf[strt+i];
     printf("[");
     putchar(ch_out);
     printf("]");
    printf("(");
    showbits(ch_out);printf(")---");
  }
 // }
 // else
 // {
 /*   for (i=32; i<64; i++)
  {
   if(i%32==0)
 printf("\n-------------------------------------------------\n");
 if(i==40||i==43||i==44||i==54||i==56||i==58||i==60)
 printf("\n\n");
     ch_out = buf[strt+i];
    printf("[");
    putchar(ch_out);
    printf("]");
    printf("(");
    showbits(ch_out);printf(")---");
  }

  }*/

  getch();
  }
//  printf("\n\n");
//  getch();
  }
//  printf("\n");
//  getch();
  return(0);
}
Ejemplo n.º 22
0
inline void startcode(void)
{
    bitpos=(bitpos+7)&~7;
    while (showbits(24)!=1)
        flushbits(8);
}
Ejemplo n.º 23
0
int main()
{
	unsigned int X = 8;
	unsigned char n=2;
	char Exercise;

	char testing = 'Y';
	while (testing == 'Y' || testing == 'y')
	{
		printf("Please choose one of the optional scenarios: \n");
		printf("\t*  1 * - setBit\n");
		printf("\t*  2 * - clearBit\n");
		printf("\t*  3 * - isPowerOfTwo\n");
		printf("\t*  4 * - checkOneBitSet\n");
		printf("\t*  5 * - checkParity\n");


		Exercise = getchar();

		printf("\nOld value : %x\n", X);
		showbits(X);
		switch (Exercise)
		{
		case '1': //Ex 2B1:
			while (getchar() != '\n');
			printf("\nposition n=%d : \n", n);
			printf("\nEx 2B1 - setBit\n");
			setBit(X, n);
			break;
		case '2'://Ex 2B2:
			while (getchar() != '\n');
			printf("\nposition n=%d : \n", n);
			printf("\nEx 2B2 - clearBit\n");
			clearBit(X, n);
			break;
		case '3'://Ex 2B3:
			while (getchar() != '\n');
			printf("\nEx 2B3 - isPowerOfTwo\n");
			printf("\n(isPowerOfTwo)\nX = %x\nis PowerOf Two?\nYES->(1);\nNO ->(0);\nRESULT: %d\n", X, isPowerOfTwo(X));
			break;
		case '4'://Ex 2B4:
			while (getchar() != '\n');
			printf("Ex 2B4 - checkOneBitSet\n");
			//isn't this the same function as power of 2?. 
			printf("\n(checkOneBitSet)\nX = %x\nYES->(1);\nNO ->(0);\nRESULT: %d\n", X, isPowerOfTwo(X));
			break;
		case '5'://Ex 2B5:
			while (getchar() != '\n');
			printf("\nEx 2B5:\ncheckParity:\n%d\n", checkParity(X));
			break;

		}

		printf("Press any key to continue ... :) \n");
		while (getchar() != '\n');
		do
		{
			printf("Do you want to continue: 'Y' or 'y' and 'N' or 'n':\t");
			testing = getchar();
			while (getchar() != '\n');
		} while ((testing != 'Y') && (testing != 'N') && (testing != 'y') && (testing != 'n'));

		//testing = 'N';
	}
	//getchar();

	//Ex 2B6:
	printf("\nEx 2B6 swap\n");
	int a = 5, b = 3;
	
	printf("\nOld: a = %d, b = %d\n", a, b);

	//bynary
	a = a^b;
	b = b^a;
	a = a^b;

	printf("\nNew(Binary ^) :\n a = %d, b = %d\n", a, b);
	

	//decimal
	a = 5;
	b = 3;
	a = a + b;
	b = a - b;
	a = a - b;

	printf("\nNew(Decimal '+', '-') A shiukd be max INT / 2 or it'll lose data from overflow :\n a = %d, b = %d\n", a, b);
	


	getchar();
	return 0;
}
Ejemplo n.º 24
0
void setBit(int X, unsigned char position) //function that sets bit with position('position') in variable('x') to 1; 
{
	X |= 1u << position;
	printf("\nNew value (setBit) : %x\n", X);
	showbits(X);
}