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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [utils/] [bin2hex.c] - Blame information for rev 25

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

Line No. Rev Author Line
1 25 julius
#include <stdio.h>
2
#include <stdlib.h>
3
 
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
                fprintf(stderr,"no input file specified\n");
20
                exit(1);
21
        }
22
        if(argc > 2) {
23
                fprintf(stderr,"too many input files (more than one) specified\n");
24
                exit(1);
25
        }
26
 
27
        fd = fopen( argv[1], "r" );
28
        if (fd == NULL) {
29
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
30
                exit(1);
31
        }
32
 
33
        while ((c = fgetc(fd)) != EOF) {
34
                printf("%.2x", (unsigned int) c);
35
                if (++i == BREAK) {
36
                        printf("\n");
37
                        i = 0;
38
                }
39
        }
40
 
41
        return 0;
42
}

powered by: WebSVN 2.1.0

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