can somone please help me with this code?

This is a discussion on can somone please help me with this code? within the C Programming forums, part of the General Programming Boards category; This is the main code for a morse code files decoder. From my understanding, it checks each bit in the ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    6

    can somone please help me with this code?

    This is the main code for a morse code files decoder. From my understanding, it checks each bit in the binary file, maps it against a decoding table to find its alphabet equivalence and then returns the output. I'm not sure if I've got this right though? Can someone help to explain to me the main parts of this code?
    Thanks

    Code:
    char *decode_file(unsigned char *input, int inputsize, int *outputsize)
    	{
    	unsigned short masks[7] = {0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80};
    	int inpos = 0;
    	int outpos = 0;
    	short buff = 0;
    	int bitsleft = 0;
    	int i;
    	char *outputbuf;
    
    	struct decoding decoding_table[27];
    	build_decoding_table(decoding_table);
    	
    	outputbuf = malloc((8*inputsize)/3 + 1);
    	memset(outputbuf, 0, (8*inputsize)/3 + 1);
    	
    	while (inpos < inputsize)
    		{
    		while (bitsleft < 9)
    			{
    			int in = input[inpos++];
    			buff |= in << (8-bitsleft);
    			bitsleft += 8;
    			}
    		
    		for(i = 0; i < 27; i++)
    			{
    			char d_char = decoding_table[i].character;
    			unsigned short d_bits = decoding_table[i].bits;
    			int d_len = decoding_table[i].length;
    			
    			if ((buff & masks[d_len-3]) == d_bits)
    				{
    				buff = buff << d_len;
    				bitsleft -= d_len;
    				outputbuf[outpos++] = d_char;
    				i = -1; continue;
    				}
    			}
    		if (inpos < inputsize && bitsleft > 8)
    			{
    			/*printf("\nDecoding failed at byte %d of %d\n", inpos, inputsize);*/
    			break;
    			}
    		}
    	*outputsize = outpos;
    	return outputbuf;
    	}

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    6
    can anyone tell me if I'm thinking in the right line?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21