2011年1月12日(水) 22:11
----------------------ここから----------------------
#include <stdio.h>
#include <stdlib.h>
#define bits(x) ((x) < 0 ? 0 : (buf[(x)/8]>>((x)%8))&0x1)
#define max(x, y) (((x) > (y)) ? (x) : (y))
int main(int argc, char *argv[])
{
FILE *fp;
unsigned char buf[255];
int i, max_on, max_off, on, off, count;
if( argc != 2 ) exit(1);
if( !(fp = fopen(argv[1], "rb")) ) exit(1);
fread(buf, sizeof(unsigned char), 240, fp);
max_on = max_off = on = off = count = 0;
for( i = 0; i < 240*8; i++ ) {
if( bits(i) ) {
if( bits(i-1) ) on++;
else {
if( i ) {
count++;
printf("%-3d, " , off);
if( (count % 8) == 7 ) printf("\n");
} else count--;
max_off = max(max_off, off);
on = 1;
}
} else {
if( bits(i-1) ) {
count++;
printf("%-3d, ", on);
if( (count % 8) == 7 ) printf("\n");
max_on = max(max_on, on);
off = 1;
} else off++;
}
}
if( bits(i-2) == bits(i-1) ) {
if( bits(i-1) ) {
printf("%-3d\n", on);
max_on = max(max_on, on);
} else {
printf("%-3d\n", off);
max_off = max(max_off, off);
}
}
printf("max on bit %d, off bit %d\n", max_on, max_off);
}
----------------------ここまで----------------------
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
MySketch 2.7.2 written by 夕雨