void process()
{
     unsigned long long v1[100],v2[100];
     long a,b,i,j;
     a=minbase(n1);
     b=minbase(n2);
     for(i=a;i<=36;i++)
     {
       v1[i]=todec(n1,i);
     }
      for(j=b;j<=36;j++)
      {
         v2[j]=todec(n2,j);
      }
      for(i=a;i<=36;i++)
       for(j=b;j<=36;j++)
       {
          if(v1[i]==v2[j])
          {
            printf("%s (base %ld) = %s (base %ld)\n",n1,i,n2,j);
            return;
          }
       }
       printf("%s is not equal to %s in any base 2..36\n",n1,n2);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    sym['I'] = 1;
    sym['V'] = 5;
    sym['X'] = 10;
    sym['L'] = 50;
    sym['C'] = 100;
    sym['D'] = 500;
    sym['M'] = 1000;
    num[1] = 'I';
    num[5] = 'V';
    num[10] = 'X';
    num[50] = 'L';
    num[100] = 'C';
    num[500] = 'D';
    num[1000] = 'M';
    int t, i, sum, cas = 0;
    char str[64];
    while(scanf("%d", &t)  && t)
    {
        ++cas;
        sum = 0;
        for(i = 0; i < t; i++)
        {
            scanf("%s", str);
            sum  += todec(str);
        }
        printf("Case ");
        torome(cas);
        printf(": ");
        torome(sum);
        printf("\n");
    }
    return 0;
}
Exemplo n.º 3
0
Arquivo: atags.c Projeto: 7ym0n/note
static void print_atag_initrd2(struct atag_initrd2 *data)
{
	console_write("  Address: 0x");
	console_write(tohex(data->address, 4));
	console_write(" - 0x");
	console_write(tohex(data->address+data->size-1, 4));
	console_write(" (");
	console_write(todec(data->size, 0));
	console_write(" bytes)\n");
}
Exemplo n.º 4
0
ostream _FAR & ostream::operator<< (long l)
{
    char buf[MaxCharsInLong];   // result of conversion
    char *prefix = 0;           // displayed numeric prefix string
    char *p;

    // find conversion base
    int base = (flags() & ios::hex) ? 16 : ((flags() & ios::oct) ? 8 : 10);

    // do we treat this as negative?  (oct and hex are unsigned)
    int neg = base == 10  &&  l < 0;

    // value to use, exclusive of sign
    unsigned long ul = neg ? -l : l;

    if( base == 10 )
        {
        p = todec(buf + MaxCharsInLong - 1, ul);

        // compute any sign prefix
        if( ul )
            if( neg )
                prefix = "-";
            else if( flags() & ios::showpos )
                prefix = "+";
        }
    else if( base == 16 )
        {
        int upper = (flags() & ios::uppercase) != 0;
        p = tohex(buf + MaxCharsInLong - 1, ul, upper);

        // compute any base prefix
        if( flags() & ios::showbase )
            prefix = upper ? "0X" : "0x";
        }
    else /* base == 8 */
        {
        p = tooct(buf + MaxCharsInLong - 1, ul);

        // compute any base prefix
        if( flags() & ios::showbase )
            prefix = "0";
        }

    // now we have a formatted string for output, to be possibly padded
    outstr((char*)p, prefix);
    return *this;
}
Exemplo n.º 5
0
Arquivo: process.c Projeto: 7ym0n/note
// Just some counting for easy debug on the screen. Simulate user process.
void sample_process_1() {
    
    console_write("Starting process 1 ");
    
    int to = 300;
    
    int i, j;
    for (i=0; i<to; i++) {
        console_write(todec(i,0));
        console_write(" ");
        for (j=0; j<to*to; j++) {
			asm volatile("NOP");
		}
    }
    
    // Call software interrupt #0 (terminate)
    asm volatile("SWI #0");
}
Exemplo n.º 6
0
// format and insert an unsigned long
ostream _FAR & ostream::operator<< (unsigned long ul)
{
    char buf[MaxCharsInLong];
    char *prefix = 0;       // displayed numeric prefix string
    char *p;


    if( flags() & ios::hex )
        {
        int upper = (flags() & ios::uppercase) != 0;
        p = tohex(buf + MaxCharsInLong - 1, ul, upper);

        // compute any base prefix
        if( flags() & ios::showbase )
            prefix = upper ? "0X" : "0x";
        }
    else if( flags() & ios::oct )
        {
        p = tooct(buf + MaxCharsInLong - 1, ul);

        // compute any base prefix
        if( flags() & ios::showbase )
            prefix = "0";
        }
    else
        {
        p = todec(buf + MaxCharsInLong - 1, ul);

        // compute any sign prefix
        if( ul  &&  (flags() & ios::showpos) )
            prefix = "+";
        }

    // now we have a formatted string for output, to be possibly padded
    outstr((char*)p, prefix);
    return *this;
}
Exemplo n.º 7
0
Arquivo: atags.c Projeto: 7ym0n/note
static void print_atag_videolfb(struct atag_videolfb *data)
{
	console_write("  Size: ");
	console_write(todec(data->width, 0));
	console_write("x");
	console_write(todec(data->height, 0));
	console_write(", depth: ");
	console_write(todec(data->depth, 0));
	console_write("bpp, linelength: ");
	console_write(todec(data->linelength, 0));

	console_write("\n  Address: 0x");
	console_write(tohex(data->address, 4));
	console_write(" - 0x");
	console_write(tohex(data->address+data->size-1, 4));
	console_write(" (");
	console_write(todec(data->size, 0));
	console_write(" bytes)\n");

	console_write("  Pos/size: R ");
	console_write(todec(data->redpos, 0));
	console_write("/");
	console_write(todec(data->redsize, 0));

	console_write(", G ");
	console_write(todec(data->greenpos, 0));
	console_write("/");
	console_write(todec(data->greensize, 0));

	console_write(", B ");
	console_write(todec(data->bluepos, 0));
	console_write("/");
	console_write(todec(data->bluesize, 0));

	console_write(", reserved ");
	console_write(todec(data->reservedpos, 0));
	console_write("/");
	console_write(todec(data->reservedsize, 0));

	console_write("\n");
}
Exemplo n.º 8
0
Arquivo: atags.c Projeto: 7ym0n/note
static void print_atag_revision(struct atag_revision *data)
{
	console_write("  Board revision: ");
	console_write(todec(data->revision, 0));
	console_write("\n");
}
Exemplo n.º 9
0
void
zpcgetuint64(struct zpctoken *token, const char *str, char **retstr)
{
    char     *ptr = (char *)str;
    uint64_t  u64 = 0;

    if (*ptr == '0') {
        ptr++;
        if (*ptr == 'x' || *ptr == 'X') {
            /* hexadecimal value */
            ptr++;
            while (isxdigit(*ptr)) {
                u64 <<= 4;
                u64 += tohex(*ptr);
                ptr++;
            }
            token->radix = 16;
            token->data.ui64.u64 = u64;
        } else if (*ptr == 'b' || *ptr == 'B') {
            /* binary value */
            ptr++;
            while (isxdigit(*ptr)) {
                u64 <<= 1;
                u64 += tobin(*ptr);
                ptr++;
            }
            token->radix = 2;
            token->data.ui64.u64 = u64;
        } else if (isdigit(ptr[1])){
            /* octal value */
            while (isxdigit(*ptr)) {
                u64 <<= 3;
                u64 += tooct(*ptr);
                ptr++;
            }
            token->radix = 8;
            token->data.ui64.u64 = u64;
        }
    } else if (isdigit(*ptr)) {
        /* decimal value */
        while (isdigit(*ptr)) {
            u64 *= 10;
            u64 += todec(*ptr);
            ptr++;
        }
        token->radix = 10;
        token->data.ui64.u64 = u64;
#if 0
    } else if (isxdigit(*ptr)) {
        while (isxdigit(*ptr)) {
            u64 <<= 4;
            u64 += tohex(*ptr);
            ptr++;
        }
        token->data.ui64.u64 = u64;
#endif
    }
    if (*ptr == 'u' || *ptr == 'U' || *ptr == ',') {
        ptr++;
    }
    token->type = ZPCUINT64;
    *retstr = (char *)ptr;

    return;
}