Help converting Binary to decimal (1 Viewer)

mikhail

Senior Member
Jan 24, 2003
9,575
#1
Hi guys,

does anyone have or know of a utility to convert a file consisting of a load of 8-bit binary numbers into their equivalent decimal numbers? I'd whip up something myself, only I don't have a complier at the moment. :down:

Any help would be appreciated.
 
OP
OP
mikhail

mikhail

Senior Member
Jan 24, 2003
9,575
#2
Alrighty, anyone with a C compiler? I have no idea if this will even compile, but could you try this?

PHP:
#include <stdio.h>
#include <file.h>

int main(void)
{
  FILE *fp1;
  int i, data[1000];

  fopen(fp1, "psd.txt", "r");
  for(i=0; i<1000; i++){
     fscanf("%d", &data[i]);
  }
  fclose(fp1);
  fopen(fp1, "psd_dec.csv", "w");
  for(i=0; i<1000; i++){
     fprintf(fp1, "%d,", data[i]);
  }
  return(0);
}
 

Martin

Senior Member
Dec 31, 2000
56,859
#3
Don't know jack about c myself, but gcc doesn't like it:

Code:
$ gcc bin.c
bin.c:2:18: file.h: No such file or directory
bin.c: In function `main':
bin.c:16: warning: passing arg 1 of `fopen' from incompatible pointer type
bin.c:16: error: too many arguments to function `fopen'
bin.c:20: warning: passing arg 1 of `fscanf' from incompatible pointer type
bin.c:20: warning: passing arg 2 of `fscanf' from incompatible pointer type
bin.c:26: warning: passing arg 1 of `fopen' from incompatible pointer type
bin.c:26: error: too many arguments to function `fopen'
 
OP
OP
mikhail

mikhail

Senior Member
Jan 24, 2003
9,575
#5
Okay, I think this is better:

PHP:
#include <stdio.h>
#include <file.h>

int main(void)
{
  FILE *fp1;
  int i, data[1000];

  fp1 = fopen("psd.txt", "r");
  for(i=0; i<1000; i++){
     fscanf("%d", &data[i]);
  }
  fclose(fp1);
  fp1 = fopen("psd_dec.csv", "w");
  for(i=0; i<1000; i++){
     fprintf(fp1, "%d,", data[i]);
  }
  return(0);
}
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)