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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orp/] [orp_soc/] [sw/] [utils/] [bin2hex.c] - Blame information for rev 1779

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

Line No. Rev Author Line
1 968 lampret
#include <stdio.h>
2 1289 partain
#include <stdlib.h>
3 968 lampret
 
4
/* Number of bytes before line is broken
5
   For example if target flash is 8 bits wide,
6
   define BREAK as 1. If it is 16 bits wide,
7
   define it as 2 etc.
8
*/
9
#define BREAK 1
10
 
11
int main(int argc, char **argv)
12
{
13
 
14
        FILE  *fd;
15
        int c;
16
        int i = 0;
17
 
18
        if(argc < 2) {
19 1289 partain
                fprintf(stderr,"no input file specified\n");
20 968 lampret
                exit(1);
21
        }
22 1289 partain
        if(argc > 2) {
23
                fprintf(stderr,"too many input files (more than one) specified\n");
24
                exit(1);
25
        }
26 968 lampret
 
27
        fd = fopen( argv[1], "r" );
28 1289 partain
        if (fd == NULL) {
29
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
30
                exit(1);
31
        }
32
 
33 968 lampret
        while ((c = fgetc(fd)) != EOF) {
34 1289 partain
                printf("%.2x", (unsigned int) c);
35 968 lampret
                if (++i == BREAK) {
36
                        printf("\n");
37
                        i = 0;
38
                }
39
        }
40 1289 partain
 
41 968 lampret
        return 0;
42
}

powered by: WebSVN 2.1.0

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