CRC-16 Hash Generator

Data Input
Sample
CRC-16 Hash Output

CRC-16 Hash Generator Manual

Purpose of the Tool

The CRC-16 Hash Generator is a free online tool that generates checksum values for any given input string. It is designed to provide a simple and efficient way to generate a checksum using the CRC-16 algorithm.

Benefits and Advantages

Using the CRC-16 Hash Generator provides several benefits and advantages such as:

  • It is online and free, with no system and software dependencies.
  • Can Clear, Can Copy, and Have Sample for ease of use.
  • The generated checksum is secure and can only be computed locally, ensuring data security.

How to Use the Tool

  1. Visit the CRC-16 Hash Generator webpage on your browser.
  2. In the input box provided, enter the string for which you want to calculate the checksum value.
  3. Click the Generate button to compute the checksum value.
  4. The computed checksum value will be displayed in the output box.
  5. You can copy this value to the clipboard or clear the input and output boxes by clicking the Clear button.

Implementation in Various Programming Languages

The following are sample codes and descriptions on how to implement the CRC-16 Hash Generator in Python, Java, JavaScript, Golang, Ruby, and PHP.

Python

import binascii

def crc16(data: bytes) -> int:
    crc = 0xFFFF
    for i in range(len(data)):
        crc ^= data[i] << 8
        for j in range(8):
            if crc & 0x8000:
                crc = (crc << 1) ^ 0x1021
            else:
                crc <<= 1
    return crc & 0xFFFF

input_str = "Free Online Tools"
input_bytes = input_str.encode('utf-8')
checksum = crc16(input_bytes)
print(hex(checksum)[2:].zfill(4)) # Output: "2dd2"

Java

import java.util.zip.CRC32;

public class CRC16HashGenerator {
    public static void main(String[] args) {
        String inputStr = "Free Online Tools";
        byte[] inputBytes = inputStr.getBytes();
        CRC32 crc32 = new CRC32();
        crc32.update(inputBytes);
        System.out.println(Long.toHexString(crc32.getValue() & 0xFFFF));
    }
}

JavaScript

function crc16(str) {
  let crc = 0xffff;
  for (let i = 0; i < str.length; i++) {
    crc ^= str.charCodeAt(i) << 8;
    for (let j = 0; j < 8; j++) {
      if (crc & 0x8000) {
        crc = (crc << 1) ^ 0x1021;
      } else {
        crc <<= 1;
      }
    }
  }
  return (crc & 0xffff).toString(16).padStart(4, "0");
}

let inputStr = "Free Online Tools";
let checksum = crc16(inputStr);
console.log(checksum); // Output: "2dd2"

Golang

package main

import (
    "hash/crc32"
    "fmt"
)

func main() {
    inputStr := "Free Online Tools"
    inputBytes := []byte(inputStr)
    crcTable := crc32.MakeTable(0x1021)
    checksum := crc32.Update(0xFFFF, crcTable, inputBytes)
    fmt.Printf("%04x\n", checksum)
}

Ruby

def crc16(str)
  crc = 0xFFFF
  str.each_byte do |b|
    crc ^= b << 8
    for j in 0..7
      if (crc & 0x8000) != 0
        crc = ((crc << 1) ^ 0x1021)
      else
        crc = (crc << 1)
      end
    end
  end
  crc & 0xFFFF
end

input_str = "Free Online Tools"
checksum = crc16(input_str).to_s(16).rjust(4, '0')
puts checksum # Output: "2dd2"

PHP

function crc16($str) {
  $crc = 0xFFFF;
  for ($i = 0; $i < strlen($str); $i++) {
    $crc ^= ord($str[$i]) << 8;
    for ($j = 0; $j < 8; $j++) {
      if ($crc & 0x8000) {
        $crc = (($crc << 1) ^ 0x1021);
      } else {
        $crc = $crc << 1;
      }
    }
  }
  return str_pad(dechex($crc & 0xFFFF), 4, "0", STR_PAD_LEFT);
}

$input_str = "Free Online Tools";
$checksum = crc16($input_str);
echo $checksum; // Output: "2dd2"

Conclusion

The CRC-16 Hash Generator is a simple yet powerful tool that can help you generate checksum values for your input strings. By using this tool, you can ensure that your data is secure and that the computed checksum value is only available locally. With the sample implementation codes provided, you can easily integrate this tool into your projects and applications.

Frequently Asked Questions (FAQ)

Meet our more Tools