fastmike 0 Newbie Poster

Hi all. i am new in this forum. i just recently bought a book Java how to program and was on chapter 2 just the basic programming until i came up with an assignment to encode a character into hamming code, which means if the user inputs H the out put should convert this char into ASCII which is (1001000) and then convert it into checkbits using hammingcode which is ( 00110010000). now here is the code which me and my couple other friends have been working on it i will post it below but this code just converts a char into ASCII not into Checkbits.

public class printBits2{
        public static void main( String args[] ){
                printBits2 pb = new printBits2( args[ 0 ] );
        }
        public printBits2( String message ){
                System.out.print( message + "\n\n" );
                char chA[] = new char[ message.length() ];
                chA = message.toCharArray();
                char displayMask = 1 << 15;
                for( int i = 0; i < message.length(); i++ ){
                        System.out.print( chA[ i ] + "\n" );
                        printCharBits( chA[ i ] );
                        System.out.print( "\n" );
                }
        }
   private void printCharBits( char c ){
                int displayMask = 1 << 15;
                for ( int bit = 1; bit < 17; bit++ ){
                        if( ( c & displayMask ) == 0 ){
                                System.out.print( "0" );
                                if( bit % 8 == 0 ){ System.out.print( " " ); }
                        }
                        else{
                                System.out.print( "1" );
                                if( bit % 8 == 0 ){ System.out.print( " " ); }
                        }
                        c <<= 1;
                }
                System.out.print( "\n" );
        }
}

it works perfect. now the hard part came to convert ascii into checkbits(hammingcode). we are not perfect in java noone in my group is but we know c++ so i got alot of help with my instructor also because of syntax errors. here is my theory what i am going to do with the hammingcode may be you guys can tell me if it is rite or not.

public int HammingEncode () {
         char mask = 1 >> 15;
        for ( int i = 16; i > 0; i--) //16 bits starting from right to left 
{ 
       if ( i==16 ||; i==15 ||;  i==14 ||;  i==13 ||;  i==12 ||; 
 i==11 ||;  i==10 ||;  i==9 ||;  i==8 ||;  i==7 ||;  i==6 ||;  i==5 ||;  i==4 ||;  i==3 ||;  i==2 ||;  i==1 ; 
  message.length(i);
 
else
        skip //( i dont know how to skip that number if it is 0)
//compute parity bits

This is what i have for the time being. if anyone can give me more specific idea that would be great and i am just a beginner in java.
Thanks alot for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.