Advertisement
OneNight

CRC-16 Poly=0x3D65

Apr 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. //POLY=0x3D65 INIT=0x0000 REFIN=FALSE REFOUT=FALSE
  2. public class HelloWorld
  3. {
  4.   private static int crc = 0;
  5.  
  6.   public static void main(String[] args)
  7.   {
  8.     byte[] bytes = new byte[] {0x73, 0x65, 0x74, 0x79, 0x62, 0x20, 0x32, 0x33, 0x3D, 0x68, 0x74, 0x67, 0x6E, 0x65, 0x6C, 0x20, 0x2C, 0x65, 0x67, 0x61,
  9.                 0x73, 0x73, 0x65, 0x6D, 0x20, 0x73, 0x69, 0x20, 0x73, 0x69, 0x68, 0x54};
  10.         calc(bytes);
  11.  
  12.         System.out.println(Integer.toHexString(crc));
  13.   }
  14.  
  15.  
  16.      public static void calc(final byte[] input) {
  17.         for (int i = 0; i < input.length; i++) {
  18.             crc ^= input[i] << 8;
  19.  
  20.             for (int j = 0; j < 8; j++)
  21.                 crc = ((crc & 0x8000) == 0) ? crc << 1 : (crc << 1) ^ 0x3D65;
  22.             crc &= 0xFFFF;
  23.         }
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement