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

Subversion Repositories avr_hp

[/] [avr_hp/] [trunk/] [c_code/] [convert_hex2dec.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
//
2
// EDAptability, SynEDA, Version 3.0.0, 2008\11\1
3
//
4
 
5
#include <stdlib.h>
6
#include <math.h>
7
#include <stdio.h>
8
#include <time.h>
9
FILE *dec;
10
FILE *hex;
11
 
12
int main(int argc, char *argv[])
13
{
14
        int c;
15
        int stat1 = 0;
16
        int stat2 = 0;
17
        int count = 0;
18
        int entries = 0;
19
        dec = fopen("a.dec","w");
20
        hex = fopen("a.hex","r");
21
        while (1)
22
        {
23
                c = getc(hex);
24
                if (c == -1)
25
                {
26
                        break;
27
                }
28
                if (    (c == ' ')      |
29
                        (c == '\t')     |
30
                        (c == '\n')     |
31
                        (c == '_')      |
32
                        (c == ',')      |
33
                        (c == ':')      |
34
                        (c == 13)       |
35
                        (c == 10)       )
36
                {
37
                        stat1 = 0;
38
                        stat2 = 0;
39
                        count = 0;
40
                } else
41
                {
42
                        if (stat1 == 0)
43
                        {
44
                                if (stat2 == 7)
45
                                {
46
                                        stat1 = 1;
47
                                        stat2 = 0;
48
                                } else
49
                                        stat2++;
50
                        } else
51
                        if (stat1 < 9)
52
                        {
53
                                printf("%c", c);
54
                                stat2++;
55
                                if (c < 58)
56
                                        count = count * 16 + (c - 48);
57
                                else
58
                                        count = count * 16 + (c - 55);
59
                                if (stat2 == 4)
60
                                {
61
                                        printf(" %d\n", count);
62
                                        entries ++;
63
                                        stat2 = 0;
64
                                        stat1++;
65
                                        count = 0;
66
                                }
67
                        }
68
                }
69
        }
70
        fclose(hex);
71
        fprintf(dec, "%d\n", entries);
72
        hex = fopen("a.hex","r");
73
        while (1)
74
        {
75
                c = getc(hex);
76
                if (c == -1)
77
                {
78
                        break;
79
                }
80
                if (    (c == ' ')      |
81
                        (c == '\t')     |
82
                        (c == '\n')     |
83
                        (c == '_')      |
84
                        (c == ',')      |
85
                        (c == ':')      |
86
                        (c == 13)       |
87
                        (c == 10)       )
88
                {
89
                        stat1 = 0;
90
                        stat2 = 0;
91
                        count = 0;
92
                } else
93
                {
94
                        if (stat1 == 0)
95
                        {
96
                                if (stat2 == 7)
97
                                {
98
                                        stat1 = 1;
99
                                        stat2 = 0;
100
                                } else
101
                                        stat2++;
102
                        } else
103
                        if (stat1 < 9)
104
                        {
105
                                //printf("%c", c);
106
                                stat2++;
107
                                if (c < 58)
108
                                        count = count * 16 + (c - 48);
109
                                else
110
                                        count = count * 16 + (c - 55);
111
                                if (stat2 == 4)
112
                                {
113
                                        fprintf(dec, "%d\n", count);
114
                                        stat2 = 0;
115
                                        stat1++;
116
                                        count = 0;
117
                                }
118
                        }
119
                }
120
        }
121
        fclose(hex);
122
        fclose(dec);
123
}
124
 

powered by: WebSVN 2.1.0

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