Ejemplo n.º 1
0
static void scan_uint(unsigned int base) {
	unsigned int i = 0;
	unsigned int c;
	
	while(1) {
		c = chr2int(*src);
		if(c >= base) /* this also includes the UINT_MAX case */
			break;
		i *= base;
		i += c;
		++src;
		++yylloc.last_column;
	}
	/* maybe we should check for whitespace or something */
	
	yylval.integer = i;
}
Ejemplo n.º 2
0
std::string strmulti2(const std::string pre)
{
    std::string val;
    int carry_over = 0;
    int tmpval;

    for (int i = pre.size()-1; i >= 0; --i){
        tmpval = chr2int(pre[i]) * 2 + carry_over;
        //std::cout << chr2int(pre[i]) << " * 2 + " << carry_over << std::endl;
        //std::cout << "tmpval : " << tmpval << std::endl;
        val.insert(0, 1, int2chr(tmpval%10));
        carry_over = tmpval / 10;
        if (i == 0 && carry_over) val.insert(0, 1, int2chr(carry_over));
        //std::cout << "carry_over : " << carry_over << std::endl;
    }

    return val;
}