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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [count.c] - Blame information for rev 365

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

Line No. Rev Author Line
1 35 rhoads
/*count.c*/
2 336 rhoads
int putchar(int value);
3 137 rhoads
int puts(const char *string);
4 35 rhoads
 
5 135 rhoads
char *name[] = {
6
   "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
7
   "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
8
   "sixteen", "seventeen", "eighteen", "nineteen",
9
   "", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
10
   "eighty", "ninety"
11 35 rhoads
};
12
 
13
char *xtoa(unsigned long num)
14
{
15
   static char buf[12];
16 135 rhoads
   int i, digit;
17
   buf[8] = 0;
18
   for (i = 7; i >= 0; --i)
19
   {
20
      digit = num & 0xf;
21
      buf[i] = digit + (digit < 10 ? '0' : 'A' - 10);
22
      num >>= 4;
23 35 rhoads
   }
24
   return buf;
25
}
26
 
27 137 rhoads
char *itoa10(unsigned long num)
28 54 rhoads
{
29
   static char buf[12];
30
   int i;
31 135 rhoads
   buf[10] = 0;
32
   for (i = 9; i >= 0; --i)
33
   {
34
      buf[i] = (char)((num % 10) + '0');
35
      num /= 10;
36 54 rhoads
   }
37
   return buf;
38
}
39
 
40 35 rhoads
void number_text(unsigned long number)
41
{
42
   int digit;
43 137 rhoads
   puts(itoa10(number));
44 35 rhoads
   puts(": ");
45 135 rhoads
   if(number >= 1000000000)
46
   {
47
      digit = number / 1000000000;
48 35 rhoads
      puts(name[digit]);
49
      puts(" billion ");
50 135 rhoads
      number %= 1000000000;
51 35 rhoads
   }
52 135 rhoads
   if(number >= 100000000)
53
   {
54
      digit = number / 100000000;
55 35 rhoads
      puts(name[digit]);
56
      puts(" hundred ");
57 135 rhoads
      number %= 100000000;
58
      if(number < 1000000)
59
      {
60 35 rhoads
         puts("million ");
61
      }
62
   }
63 135 rhoads
   if(number >= 20000000)
64
   {
65
      digit = number / 10000000;
66
      puts(name[digit + 20]);
67 35 rhoads
      putchar(' ');
68 135 rhoads
      number %= 10000000;
69
      if(number < 1000000)
70
      {
71 35 rhoads
         puts("million ");
72
      }
73
   }
74 135 rhoads
   if(number >= 1000000)
75
   {
76
      digit = number / 1000000;
77 35 rhoads
      puts(name[digit]);
78
      puts(" million ");
79 135 rhoads
      number %= 1000000;
80 35 rhoads
   }
81 135 rhoads
   if(number >= 100000)
82
   {
83
      digit = number / 100000;
84 35 rhoads
      puts(name[digit]);
85
      puts(" hundred ");
86 135 rhoads
      number %= 100000;
87
      if(number < 1000)
88
      {
89 35 rhoads
         puts("thousand ");
90
      }
91
   }
92 135 rhoads
   if(number >= 20000)
93
   {
94
      digit = number / 10000;
95
      puts(name[digit + 20]);
96 35 rhoads
      putchar(' ');
97 135 rhoads
      number %= 10000;
98
      if(number < 1000)
99
      {
100 35 rhoads
         puts("thousand ");
101
      }
102
   }
103 135 rhoads
   if(number >= 1000)
104
   {
105
      digit = number / 1000;
106 35 rhoads
      puts(name[digit]);
107
      puts(" thousand ");
108 135 rhoads
      number %= 1000;
109 35 rhoads
   }
110 135 rhoads
   if(number >= 100)
111
   {
112
      digit = number / 100;
113 35 rhoads
      puts(name[digit]);
114
      puts(" hundred ");
115 135 rhoads
      number %= 100;
116 35 rhoads
   }
117 135 rhoads
   if(number >= 20)
118
   {
119
      digit = number / 10;
120
      puts(name[digit + 20]);
121 35 rhoads
      putchar(' ');
122 135 rhoads
      number %= 10;
123 35 rhoads
   }
124
   puts(name[number]);
125 135 rhoads
   putchar ('\r');
126
   putchar ('\n');
127 35 rhoads
}
128
 
129 137 rhoads
 
130
int main()
131 35 rhoads
{
132 137 rhoads
   unsigned long number, i=0;
133
 
134 135 rhoads
   number = 3;
135
   for(i = 0;; ++i)
136
   {
137 35 rhoads
      number_text(number);
138 135 rhoads
      number *= 3;
139 137 rhoads
      //++number;
140 35 rhoads
   }
141
}
142
 

powered by: WebSVN 2.1.0

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