fork download
  1. public class crc
  2. { public static byte crc8 (String stringData)
  3. {
  4. int len = stringData.length();
  5. int i = 0;
  6. byte crc = 0x00;
  7. while (len-- > 0) {
  8. byte extract = (byte) stringData.charAt(i++);
  9. for (byte tempI = 8; tempI != 0; tempI--) {
  10. byte sum = (byte) ((crc & 0xFF) ^ (extract & 0xFF));
  11. sum = (byte) ((sum & 0xFF) & 0x01);
  12. crc = (byte) ((crc & 0xFF) >>> 1);
  13. if (sum != 0) {
  14. crc = (byte)((crc & 0xFF) ^ 0x8C);
  15. }
  16. extract = (byte) ((extract & 0xFF) >>> 1);
  17. }
  18. }
  19. return crc;
  20. }
  21.  
  22. public static void main (String args[])
  23. {
  24. String msg = "101011001";
  25. byte crc8result = crc8(msg);
  26.  
  27. String s1 = String.format("%8s", Integer.toBinaryString(crc8result & 0xFF)).replace(' ', '0');
  28. System.out.println(s1); // 10000001
  29. String mesgWithCRC = msg + s1;
  30. System.out.println(mesgWithCRC);
  31.  
  32. byte newCrc8Result = crc8(mesgWithCRC);
  33. String s2 = String.format("%8s", Integer.toBinaryString(newCrc8Result & 0xFF)).replace(' ', '0');
  34. System.out.println(s2); // 10000001
  35.  
  36. }
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class crc is public, should be declared in a file named crc.java
public class crc
       ^
1 error
stdout
Standard output is empty