Needing to write a small C programme to number crunch
(hate C)
I have these numbers
aa 00 3d fe cd ff 22 00 3d aa 00 39 fe c4 ff 1f
aa is my placemarker as it is a serial stream, next 6 bytes are my numbers, 2s compliment so that makes it
003d fecd ff22
First one is +ve, second 2 are negative. The next 2 bytes in teh string are a bug in the chip and can be discarded then it starts again.
I can
num = fgetc (infile);
printf ("%d", num);
and it prints a number between -128 and +128 but
x = fgetc (infile);
x = x << 8;
x = x + fgetc (infile);
That gives me a number between 0 and 65535 ie always +ve.
I want to stick these numbers in a file with 3 columns of decimal numbers between -32k and +32k
What printf format do I need?
(hate C)I have these numbers
aa 00 3d fe cd ff 22 00 3d aa 00 39 fe c4 ff 1f
aa is my placemarker as it is a serial stream, next 6 bytes are my numbers, 2s compliment so that makes it
003d fecd ff22
First one is +ve, second 2 are negative. The next 2 bytes in teh string are a bug in the chip and can be discarded then it starts again.
I can
num = fgetc (infile);
printf ("%d", num);
and it prints a number between -128 and +128 but
x = fgetc (infile);
x = x << 8;
x = x + fgetc (infile);
That gives me a number between 0 and 65535 ie always +ve.
I want to stick these numbers in a file with 3 columns of decimal numbers between -32k and +32k
What printf format do I need?


Comment