예제 #1
0
std::string NumConverter::ToHex() {
    if (NumSys == hex) {
        return Val;
    } else {
        std::string s("");
        if (NumSys == dec) {
            s = Val;
            int tmp = atoi(s.c_str());
            char buf[32];
            snprintf(buf, sizeof(buf), "%x", tmp);
            s = buf;
        }
        if (NumSys == bin) {
            s = BinToDec(Val);
            int tmp = atoi(s.c_str());
            char buf[32];
            snprintf(buf, sizeof(buf), "%x", tmp);
            s = buf;
        }
        if (NumSys == oct) {
            s = OctToDec(Val);
            int tmp = atoi(s.c_str());
            char buf[32];
            snprintf(buf, sizeof(buf), "%x", tmp);
            s = buf;
        }
        return s;
    }
}
예제 #2
0
// If there are 4, 5, or 6, letters convert whole binary string
// If there are 7 letters, convert the first 6, then convert the 7th
// It provides n-1 letters
std::string BASE93::BinTo93(std::string result, int length)
{
	int i = 0, j = (length * BinaryBondary);
	// convert all of binary strings 4, 5, and 6
	if (length < 7)
		return CompressNumber(BinToDec(result.substr(i, j)));
	// special case 7
	std::string temp = "";
	// convert binary strings 4-6
	j = 30;
	temp += CompressNumber(BinToDec(result.substr(i, j)));
	if (temp.size() == 4) temp += "*";
	// convert 7th binary string
	i = 30;
	j = 35;
	return (temp + CompressNumber(BinToDec(result.substr(i, j))));
}
예제 #3
0
파일: timer.c 프로젝트: apandit/RTOS
/*
 * Entry point, check with m68k-coff-nm
 */
int main( void )
{
    UINT32 mask;

    /* Disable all interupts */
    asm( "move.w #0x2700,%sr" );

    coldfire_vbr_init();

    /*
     * Store the timer ISR at auto-vector #6
     */
    asm( "move.l #asm_timer_entry,%d0" );
    asm( "move.l %d0,0x10000078" );

    /*
     * Setup to use auto-vectored interupt level 6, priority 3
     */
    TIMER0_ICR = 0x9B;

    /*
     * Set the reference counts, ~10ms
     */
    TIMER0_TRR = 1758;

    /*
     * Setup the timer prescaler and stuff
     */
    TIMER0_TMR = 0xFF1B;

    /*
     * Set the interupt mask
     */
    mask = SIM_IMR;
    mask &= 0x0003fdff;
    SIM_IMR = mask;    

    /* Let the timer interrupt fire, lower running priority */
    asm( "move.w #0x2000,%sr" );
    
    rtx_dbug_outs( (CHAR *) "Timer started\n\r" );
    timer_count = 0;
	
	int seconds_count = 0;

    while ( 1 ){
		// Check that timer is at 5 seconds; reset timer in block
		// or block is evaluated true again (timer doesn't reset fast enough)
		if ( timer_count &&  timer_count % 500 == 0 ) {
            timer_count = 0;
			seconds_count += 5;

            BinToDec( seconds_count );
		}
	};
    return 0;
}
예제 #4
0
// Convert binary into a word
std::string BASE93::BinToWord(std::string binary)
{
	std::string result = "";
	int i = 0, j = 6;
	while (i < binary.size())
	{
		result += char(BinToDec(binary.substr(i, BinaryBondary)) + 96);
		i += 5;
	}
	return result;
}
예제 #5
0
void main()
{
	int num;
	scanf("%d", &num);
	num = BinToDec(num);
	DecToBin(num);
	printf("\n inverted bits = ");
	DecToBin(invert(num, 4, 3));
	printf("\n\n0^0 = %d\n", 0^0);
	printf("\n\n1^1 = %d\n", 1^1);
	printf("\n\n1^0 = %d\n", 1^0);
	printf("\n\n0^1 = %d\n", 0^1);
}
예제 #6
0
int ParseBits(int bits[], int* buffer)
{
	int counterBuffer = 0;
	int operator = 1;
	int currentGene = 0;
	int i = 0;
	for(i = 0; i < BITLENGTH; i += GENELENGTH)
	{
		currentGene = BinToDec(&bits[i]);
		if(debug == 0)
		{
			printf("this gene %d \n", currentGene);
		}
		if(operator == 1)
		{
			if((currentGene < 10) || (currentGene > 13))
			{
				continue;
			}
			else
			{
				operator = 0;
				buffer[counterBuffer++] = currentGene;
				continue;
			}
		}
		else
		{
			if (currentGene > 9)
			{
				continue;
			}
			else
			{
				operator = 1;
				buffer[counterBuffer++] = currentGene;
				continue;
			}
		}
	}
	
	for(i = 0; i < counterBuffer; i++)
	{
		if((buffer[i] == 13) && (buffer[i + 1] == 0))
		{
			buffer[i] = 10;
		}
	}

	return counterBuffer;
}
예제 #7
0
int main()
{
	int i;
	int j;
	int k;
	int l;
	int m;
	int n;
	int t;
	char a[50];
	char b[50];
	scanf("%d\n",&t);
	for(i=0;i<t;i++)
	{
		scanf("%s %s",a,b);
		m=BinToDec(a);
		n=BinToDec(b);
		k=GCD(m,n);
		printf("Pair #%d: ",i+1);
		if(k>1) printf("All you need is love!\n");
		else printf("Love is not all you need!\n");
	}
	return 0;
}
예제 #8
0
//---------------------------------ParseBits------------------------------------------
//
// Given a chromosome this function will step through the genes one at a time and insert
// the decimal values of each gene (which follow the operator -> number -> operator rule)
// into a buffer. Returns the number of elements in the buffer.
//------------------------------------------------------------------------------------
int ParseBits(string bits, int* buffer)
{
    //counter for buffer position
	int cBuff = 0;
	// step through bits a gene at a time until end and store decimal values
	// of valid operators and numbers. Don't forget we are looking for operator -
	// number - operator - number and so on... We ignore the unused genes 1111
	// and 1110
	//flag to determine if we are looking for an operator or a number
	bool bOperator = true;
	//storage for decimal value of currently tested gene
	int this_gene = 0;
	for (int i=0; i<CHROMO_LENGTH; i+=GENE_LENGTH){
		//convert the current gene to decimal
		this_gene = BinToDec(bits.substr(i, GENE_LENGTH));
		//find a gene which represents an operator
		if (bOperator){
			if((this_gene < 10) || (this_gene > 13) ){
				continue;
            }else{
				bOperator		= false;
				buffer[cBuff++] = this_gene;
				continue;
			}
		}else{
        //find a gene which represents a number
			if(this_gene > 9){
				continue;
			}else{
				bOperator		= true;
				buffer[cBuff++] = this_gene;
				continue;
			}
		}

	}//next gene

	//	now we have to run through buffer to see if a possible divide by zero
	//	is included and delete it. (ie a '/' followed by a '0'). We take an easy
	//	way out here and just change the '/' to a '+'. This will not effect the
	//	evolution of the solution
	for (int i=0; i<cBuff; i++){
		if ( (buffer[i] == 13) && (buffer[i+1] == 0) ){
			buffer[i] = 10;
        }
	}
	return cBuff;
}
예제 #9
0
std::string NumConverter::ToDecimal() {
    if (NumSys == dec) {
        return Val;
    } else {
        std::string s("");
        if (NumSys == bin) {
            s = BinToDec(Val);
        }
        if (NumSys == oct) {
            s = OctToDec(Val);
        }
        if (NumSys == hex) {
            s = HexToDec(Val);
        }
        return s;
    }
}