Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: CRC algorithm

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default CRC algorithm

    I have a code CRC but I don't know how to use it. Cause I don't know why the code is working
    I new in Java programming.

    can other tell me how the code is working and how to use it?

    import java.util.zip.Checksum;
     
    public class crc implements Checksum {
     
    	public crc(){
    		crc = 0;
    	}
     
      private int crc;
     
     
      private static int[] crc_table = make_crc_table();
     
     
      private static int[] make_crc_table ()
      {
        int[] crc_table = new int[256];
        for (int n = 0; n < 256; n++)
          {
            int c = n;
            for (int k = 8;  --k >= 0; )
              {
                if ((c & 1) != 0)
                    c = 0xedb88320 ^ (c >>> 1); 
                else
                  c = c >>> 1;
              }
            crc_table[n] = c;
          }
        return crc_table;
      }
     
     
      public long getValue ()
      {
        return (long) crc & 0xffffffffL;
      }
     
      public void reset () { crc = 0; }
     
      public void update (int bval)
      {
        int c = ~crc;
        c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
        crc = ~c;
      }
     
      public void update (byte[] buf, int off, int len)
      {
        int c = ~crc;
     
        while (--len >= 0)
     
          c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
        crc = ~c;
      }
      public void printCRCTable(){
    	  int count = 0;
    	for(int printcrc :crc_table){
    	}
      }
     
      public void update (byte[] buf) { update(buf, 0, buf.length); }
     
    }

    thanks for your attention


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: CRC algorithm

    The comments in the code should tell you how it works and how to use it.
    Or you could read the API doc that came with it.
    Or you could ask the author.

Similar Threads

  1. all i need is algorithm
    By coder.freak in forum Paid Java Projects
    Replies: 3
    Last Post: April 6th, 2011, 11:11 AM
  2. SDES algorithm
    By low1988 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 2nd, 2010, 09:57 AM
  3. [SOLVED] Algorithm Help
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2010, 04:12 PM
  4. I have algorithm problem
    By Newoor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 11th, 2009, 08:11 PM
  5. algorithm
    By AmmrO in forum Algorithms & Recursion
    Replies: 13
    Last Post: September 24th, 2009, 09:18 PM