siteName > > others.CRC16
Threads
java ( 907296 ) - java ( 907301 ) stack: com.thealgorithms.others.CRC16.main(CRC16.java:10)
package com.thealgorithms.others;

/**
 * Generates a crc16 checksum for a given string
 */
public final class CRC16 {
    private CRC16() {
    }

    public static void main(String[] args) {
        System.out.println(crc16("Hello World!"));
    }

    public static String crc16(String message) {
        int crc = 0xFFFF; // initial value
        int polynomial = 0x1021; // 0001 0000 0010 0001 (0, 5, 12)
        byte[] bytes = message.getBytes();

        for (byte b : bytes) {
            for (int i = 0; i < 8; i++) {
                boolean bit = ((b >> (7 - i) & 1) == 1);
                boolean c15 = ((crc >> 15 & 1) == 1);
                crc <<= 1;
                if (c15 ^ bit) {
                    crc ^= polynomial;
                }
            }
        }
        crc &= 0xffff;
        return Integer.toHexString(crc).toUpperCase();
    }
}
Variables All
No.FromNameValue
110args[Ljava.lang.String;@7852e922
END 0 00
Output All Filter Merge
Process FilterThread Filter
907296 java 907301 java
No.PNPIDTIDTNMessage
1java907296907301java882A
END 0 0 0 00
Project:Alg-Java
Update:20240824
Commit:a7cd97d7
Source Code:others.CRC16
BuildTool:Java17
Compiler:Java17
Runtime:Openjdk17
System:MySystemD
Kernel:Linux5.10.211
Cpu:Intel:Corei7-7700K
Machine:AwesomeMachine