Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //POLY=0x3D65 INIT=0x0000 REFIN=FALSE REFOUT=FALSE
- public class HelloWorld
- {
- private static int crc = 0;
- public static void main(String[] args)
- {
- byte[] bytes = new byte[] {0x73, 0x65, 0x74, 0x79, 0x62, 0x20, 0x32, 0x33, 0x3D, 0x68, 0x74, 0x67, 0x6E, 0x65, 0x6C, 0x20, 0x2C, 0x65, 0x67, 0x61,
- 0x73, 0x73, 0x65, 0x6D, 0x20, 0x73, 0x69, 0x20, 0x73, 0x69, 0x68, 0x54};
- calc(bytes);
- System.out.println(Integer.toHexString(crc));
- }
- public static void calc(final byte[] input) {
- for (int i = 0; i < input.length; i++) {
- crc ^= input[i] << 8;
- for (int j = 0; j < 8; j++)
- crc = ((crc & 0x8000) == 0) ? crc << 1 : (crc << 1) ^ 0x3D65;
- crc &= 0xFFFF;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement