OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [test0/] [src/] [test_exec/] [atoi.h] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __ATOI_H__
2
#define __ATOI_H__
3
 
4
static inline int power(int exp, int mul)
5
{
6
        int total = 1;
7
 
8
        while (exp > 0) {
9
                total *= mul;
10
                exp--;
11
        }
12
        return total;
13
}
14
 
15
static inline int ascii_to_int(char *str)
16
{
17
        int size = strlen(str);
18
        int iter = size - 1;
19
        int num = 0;
20
 
21
        for (int i = 0; i < size; i++)
22
                num += ((int)str[iter - i] - 48) * power(i, 10);
23
        return num;
24
}
25
 
26
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.