示例#1
0
int put_super_blk(void) {
	char *convert;
	convert = calloc(4, sizeof(int));
	char *buf;
	buf = calloc(128, sizeof(char));
	int counter = 0;
	int decimal = 0;
	for(int i=0; i < 512; i++) {
		if (counter == 4) {
			counter = 0;
			decimal = binary_decimal(atoi(convert));

			super_blk_buf[i/4 - 1] = decimal;
			buf[i/4 - 1] = (char)(((int)'0')+decimal);
		}

		convert[counter] = (char)(((int)'0')+disk_bitmap[i]);
        ++counter;
	}

	// Write to memory
	int writesb = put_block(0, buf);

	return decimal;
}
示例#2
0
void multi(int *table, char *buffer){

			
		int count = 0;
		int i = 12;
		while(isdigit(buffer[i])){
			count++;
			i++;
		}
		
		char inparr[count];
		i = 12;
		int i1 = 0;
		while(i1<count){
			inparr[i1] = buffer[i];
			i1++;
			i++;
		}
		int muxnum = atoi(inparr);
		int selectnum = 0;
		int j = 1;
		while(j<muxnum){
			j = j*2;							
			selectnum++;
		}
		
		char selecters[selectnum];
		char muxinputs[muxnum];
		int o = i+1;
		i = 0;
		while(i<muxnum){
			muxinputs[i] = buffer[o];
			o = o+2;	
			i++;
		}
		i = 0;
		while(i<selectnum){
			selecters[i] = buffer[o]; 	
			o = o+2;
			i++;
		}
		int select[selectnum];
		i = 0;
		while(i<selectnum){
			select[i] = table[(int)selecters[i]];
			i++;
		}
		int selected = 0;
		for (i = 0; i < selectnum; i++){
 			selected = 10 * selected + select[i];
		}
		
		int gray = getbin(selected);
		int dex = binary_decimal(gray);
			
		table[(int)buffer[o]] = table[(int)muxinputs[dex]];
		 
}
示例#3
0
文件: test.c 项目: Sunnylunch/study
void test()
{
	DataType arr[100] = { 0 };
	int x= 0;
	int ret = 0;
	int k = 0;
	int num = 0;
	while (1)
	{
		Menu();
		scanf("%d", &x);
		switch (x)
			{
			case EXIT:
				Quit();
				break;
			case CREATE:
			    printf("请输入一个具有+-*/%^的表达式:>\n");
				CreatExpression(arr);
				break;
			case TRANSMIT:
				TransmitExpression(arr);
				break;
			case VALUATE:
				ret = EvaluateExpression();
				printf("%d\n", ret);
				break;
			case BINARY:
				printf("请输入数字:>");
				scanf("%d", &num);
				binary_system(num);
				break;
			case OCTONARY:
				printf("请输入数字:>");
				scanf("%d", &num);
				octonary_number_system(num);
				break;
			case B_DEC:
				ret=binary_decimal();
				printf("十进制数为:%d\n", ret);
				break;
			case OCT_DEC:
				ret=Octal_decimal();
				printf("十进制数为:%d\n", ret);
				break;
			default:
				printf("选择无效\n");
				break;
			}
	}
}
示例#4
0
void decoder(int *table, char *buffer){

		int count = 0;
		int i = 8;
		while(isdigit(buffer[i])){
			count++;
			i++;
		}
		
		char inparr[count];
		i = 8;
		int i1 = 0;
		while(i1<count){
			inparr[i1] = buffer[i];
			i1++;
			i++;
		}
		int inpnum = atoi(inparr);
		int outnum = poww(2,inpnum);
		char inputvars[inpnum];
		char outputvars[outnum];
		int o = i + 1;
		i = 0;
		while(i<inpnum){
			inputvars[i] = buffer[o];
			i++;
			o = o+2;
		}
		i=0;
		while(i<outnum){
			outputvars[i] = buffer[o];
			table[(int)outputvars[i]] = 0; /*set default for outputs to 0 */
			i++;	
			o = o+2;
		}
		i = 0;
		int select[inpnum];		
		while(i<inpnum){
			select[i] = table[(int)inputvars[i]];
			i++;
		}
		int selected = 0;
		for (i = 0; i < inpnum; i++){
 			selected = 10 * selected + select[i];
		}
		int gray = getbin(selected);
		int dex = binary_decimal(gray);
		table[(int)outputvars[dex]] = 1;

}
int main()
{
	int i,p,t=0;
	printf("Enter the text\n");
	//for(i=0;i<16;i++)
	scanf("%s",text);
	char str[100];
	int str1[100];
	for(i=0;i<strlen(text);i++)
		str1[i]=(int)(text[i]);
	
	printf("Enter the crossover key\n");
	for(i=0;i<2;i++){
		scanf("%d",&c[i]);
	}
	printf("Enter the mutation key\n");
	for(i=0;i<2;i++){
		scanf("%d",&m[i]);
	}	
	key[0]=c[0];  
	key[1]=c[1];
	key[2]=m[0];
	key[3]=m[1];	
	c1[0]=key[0];
	c1[1]=key[1];
	m1[0]=key[2];
	m1[1]=key[3];	
	for(i=0;i<strlen(text);i++)
		bin(str1[i]);
	k=0;	
	int j;
	while(k<g)
	{
		for(i=0;i<8;i++)
			a[i]=d[k++];
		j=0;
		for(i=8;i<16;i++)
		{
			b[j]=d[k++];
			j++;	
		}
		encrp();
			//k=k+16;
	}
	int l=0,v=0,dec[10],dec1[10],w[100],w1[100],o=0,o1=0;
	char st[100];
	printf("Text:");
	for(i=0;i<g;i++)
		printf("%d",d[i]);
	printf("\nEncrypted text:");
	for(i=0;i<g;i++)
		printf("%d",enc[i]);
	
	while(v<g1)
	{
		for(i=0;i<7;i++)
		{
			dec1[i]=enc[v++];
		}
		w1[o1++]=binary_decimal(dec1);
		
	}
	for(i=0;i<o1;i++)
	{
		st[i]=(char)(w1[i]);
	}
	st[i+1]='\0';
	printf("\n%s\n",st);
	k=0;
	while(k<g1)
	{
		for(i=0;i<8;i++)
			a[i]=enc[k++];
		j=0;
		for(i=8;i<16;i++)
		{
			b[j]=enc[k++];
			j++;	
		}
		decry();
		//k=k+16;
	}
	printf("\nDecrypted text:");
	for(i=0;i<g;i++)
		printf("%d",decr[i]);
	//printf("\n%d\t%d\t%d\n",g,g1,g2);
	
	while(l<g2)
	{
		for(i=0;i<7;i++)
		{
			dec[i]=decr[l++];
		}
		w[o++]=binary_decimal(dec);
		
	}
	for(i=0;i<o;i++)
	{
		str[i]=(char)(w[i]);
	}
	str[i+1]='\0';
	printf("\nDecrypted text=%s\n",str);
				
	return 0;
}
示例#6
0
int main()
{
	//I INPUTS AND VARIABLE DECLARATIONS 
		int t, m , p;		//The number of each arrays' element
		int i;		//Comparative Index for looping

		scanf("%d", &t);		//Scanning the number of t array's element
		puck tobi[t];		//Declaration of Tobi's big data array
		for (i = 0; i < t; i++)
		{
			scanf("%s", &tobi[i].binary);		//Input of Tobi's big data array
		}

		scanf("%d", &m);		//Scanning the number of m array's element
		puck moni[m];		//Declaration of Moni's big data array
		for (i = 0; i < m; i++)
		{
			scanf("%s", &moni[i].binary);		//Input of Moni's big data array
		}

		scanf("%d", &p);		//Scanning the number of p array's element
		puck piyu[p];		//Declaration of Piyu's big data array
		for (i = 0; i < p; i++)
		{
			scanf("%s", &piyu[i].binary);		//Input of Piyu's big data array
		}

	//II SORT EVERY ARRAY
		sorter(t, tobi);
		sorter(m, moni);		//SORT EVERYTHING!!!!!
		sorter(p, piyu);
		puck suspi[t+m+p];

	//III SCAN THE SUSPICIOUS DATA
		susscan(t, m, p, tobi, moni, piyu, suspi);		//SCAN EVERYTHING!!!!!!
		//Tact, Scan, COUNTER SHOCK!!!!

	//IV MERGE EVERY ARRAY
		puck mergres1[t+m];		//These two variable stores the merging result of three arrays
		puck mergres2[t+m+p];

		sortmerg(t, m, tobi, moni, mergres1);		//MERGE EVERYTHING!!!!!!
		sortmerg(t+m, p, mergres1, piyu, mergres2 );

	//V OUTPUT
		if (t+m+p !=0)		//If there is data, print the result
		{
			printf("Laporan Data Biner\n");		//Output bloat according to the problem
			printf("====================\n");
		}
		for (i = 0; i < t+m+p; ++i)
		{
			printf("%s\n",mergres2[i].binary);		//PRINT EVERYTHING!!!!!!!!
		}
		for (i = 0; i < susscan(t, m, p, tobi, moni, piyu, suspi); ++i)
		{
			printf("%d\n",binary_decimal(atoi(suspi[i].binary)) );		//Printing the suspicious list
		}

	return 0;
}
void main(void)
{
    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();
    select_chip(1); // Select the ADT7320

    SSPBUF = 0b00001000; // Command byte indicating a write
    buf_wait();
    SSPBUF = 0b00000000; // Write to the ADT7320 config register
    buf_wait();

    select_chip(2); // Select the AD7793 ADC

    SSPBUF = 0b00001000; // Command byte indicating a write to the
    buf_wait();          // mode register
    SSPBUF = 0b00000000; // First 8 bits of the 16 bit mode register
    buf_wait();
    SSPBUF = 0b11000001; // Second 8 bits of the mode register
    buf_wait();

    select_chip(1);
    
    SSPBUF = 0b01010000; // Command byte to read temperature
    buf_wait();
    int junc_bin = SSPBUF/1000;
    float junc_temp = 25;

    int loop_counter = 0;

    while(1)
    {
        PORTCbits.RC6 = 0b1;
        PORTCbits.RC7 = 0b1;
        PORTBbits.RB5 = 0b1;
        PORTBbits.RB4 = 0b1;
        PORTBbits.RB3 = 0b1;
        PORTBbits.RB2 = 0b1;
        PORTBbits.RB1 = 0b1;
        PORTBbits.RB0 = 0b1;

        PORTA = 0b11110111;

        for (int thermo_sel = 1; thermo_sel < 3; thermo_sel++)
        {
            select_chip(2);

            SSPBUF = 0b00010000; // Command byte indicating a write to the
            buf_wait();          // config register for the thermocouple
            SSPBUF = 0b01000110; // First 8 bits of the 16 bit config register
            buf_wait();          // for the thermocouple
            switch (thermo_sel)
            {
                case 1:
                    SSPBUF = 0b10010000; // Second 8 bits for the first thermo
                    buf_wait();
                    break;
                case 2:
                    SSPBUF = 0b10010001; // Second 8 bits for the second thermo
                    buf_wait();
                    break;

            }

            int not_ready = 1;

            while (not_ready == 1)
            {
                SSPBUF = 0b01000000; // Command byte to read status
                buf_wait();
                not_ready = SSPBUF/10000000;
            }

            SSPBUF = 0b01011000; // Command byte to read from first thermo
            buf_wait();

            float thermo_v = 0;
            for (int i=0; i<3; i++)
            {
                //thermo_v += (binary_decimal(SSPBUF) * (16 - i * 8));
            }

            junc_temp = (binary_decimal(junc_bin))/16.0;

//            if (junc_temp/1000000000000) {junc_temp = (binary_decimal(junc_bin) - 8192)/16.0;}

            float tc = temp_voltage(junc_temp) + thermo_v;

            seven_segment(voltage_temp(tc), thermo_sel);
        }

        loop_counter++;

        if (loop_counter > 100)
        {
            loop_counter = 0;
            select_chip(1);
            SSPBUF = 0b01010000; // Command byte to read temperature
            buf_wait();
            junc_bin = SSPBUF;
        }

        char* str = display_number(216.98);
        char strval[5];
        for (int i=0; i<6; i++) {strval[i] = *(str+i);}
        char digit = strval[0];
        int val = 5;
        switch (digit) {
            case 0x30:
                val = 0;
                break;
            case 0x31:
                val = 1;
                break;
            case 0x32:
                val = 2;
                break;
        }
        int result = val;
        /* TODO <INSERT USER APPLICATION CODE HERE> */
    }

}