r_punidha
August 4th, 2009, 02:31 AM
Hi,
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
typedef struct bit_file {
FILE *file;
unsigned char mask;
int rack;
int pacifier_counter;
} BIT_FILE;
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
int top_of_range;
int abs_code;
int bit_count;
if ( code == 0 ) {
OutputRunLength++;
return;
}
if ( OutputRunLength != 0 ) {
while ( OutputRunLength > 0 ) {
OutputBits( output_file, 0L, 2 );
if ( OutputRunLength <= 16 ) {
OutputBits( output_file,
(unsigned long) ( OutputRunLength - 1 ), 4 );
OutputRunLength = 0;
} else {
OutputBits( output_file, 15L, 4 );
OutputRunLength -= 16;
}
}
}
if ( code < 0 )
abs_code = -code;
else
abs_code = code;
top_of_range = 1;
bit_count = 1;
while ( abs_code > top_of_range ) {
bit_count++;
top_of_range = ( ( top_of_range + 1 ) * 2 ) - 1;
}
if ( bit_count < 3 )
OutputBits( output_file, (unsigned long) ( bit_count + 1 ), 3 );
else
OutputBits( output_file, (unsigned long) ( bit_count + 5 ), 4 );
if ( code > 0 )
OutputBits( output_file, (unsigned long) code, bit_count );
else
OutputBits( output_file, (unsigned long) ( code + top_of_range ),
bit_count );
}
void OutputBits( bit_file, code, count )
BIT_FILE *bit_file;
unsigned long code;
int count;
{
unsigned long mask;
mask = 1L << ( count - 1 );
while ( mask != 0) {
if ( mask & code )
bit_file->rack |= bit_file->mask;
bit_file->mask >>= 1;
if ( bit_file->mask == 0 ) {
if ( putc( bit_file->rack, bit_file->file ) != bit_file->rack )
printf( "Fatal error in OutputBit!\n" );
else if ( ( bit_file->pacifier_counter++ & PACIFIER_COUNT ) == 0 )
putc( '.', stdout );
bit_file->rack = 0;
bit_file->mask = 0x80;
}
mask >>= 1;
}
}
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
typedef struct bit_file {
FILE *file;
unsigned char mask;
int rack;
int pacifier_counter;
} BIT_FILE;
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
int top_of_range;
int abs_code;
int bit_count;
if ( code == 0 ) {
OutputRunLength++;
return;
}
if ( OutputRunLength != 0 ) {
while ( OutputRunLength > 0 ) {
OutputBits( output_file, 0L, 2 );
if ( OutputRunLength <= 16 ) {
OutputBits( output_file,
(unsigned long) ( OutputRunLength - 1 ), 4 );
OutputRunLength = 0;
} else {
OutputBits( output_file, 15L, 4 );
OutputRunLength -= 16;
}
}
}
if ( code < 0 )
abs_code = -code;
else
abs_code = code;
top_of_range = 1;
bit_count = 1;
while ( abs_code > top_of_range ) {
bit_count++;
top_of_range = ( ( top_of_range + 1 ) * 2 ) - 1;
}
if ( bit_count < 3 )
OutputBits( output_file, (unsigned long) ( bit_count + 1 ), 3 );
else
OutputBits( output_file, (unsigned long) ( bit_count + 5 ), 4 );
if ( code > 0 )
OutputBits( output_file, (unsigned long) code, bit_count );
else
OutputBits( output_file, (unsigned long) ( code + top_of_range ),
bit_count );
}
void OutputBits( bit_file, code, count )
BIT_FILE *bit_file;
unsigned long code;
int count;
{
unsigned long mask;
mask = 1L << ( count - 1 );
while ( mask != 0) {
if ( mask & code )
bit_file->rack |= bit_file->mask;
bit_file->mask >>= 1;
if ( bit_file->mask == 0 ) {
if ( putc( bit_file->rack, bit_file->file ) != bit_file->rack )
printf( "Fatal error in OutputBit!\n" );
else if ( ( bit_file->pacifier_counter++ & PACIFIER_COUNT ) == 0 )
putc( '.', stdout );
bit_file->rack = 0;
bit_file->mask = 0x80;
}
mask >>= 1;
}
}