From 38c104db01afdcb7d0745236dfafc21dd14a027b Mon Sep 17 00:00:00 2001 From: Rishabh Ranjan Singh Date: Tue, 4 Nov 2025 16:21:12 +0530 Subject: [PATCH 1/3] docs: Add Python binascii.crc_hqx() term entry (#7733) --- .../binascii-module/crc-hqx/crc-hqx.md | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 content/python/concepts/binascii-module/crc-hqx/crc-hqx.md diff --git a/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md b/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md new file mode 100644 index 00000000000..9f49c675e15 --- /dev/null +++ b/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md @@ -0,0 +1,80 @@ +--- +Title: '.crc_hqx()' +Description: 'Computes the CRC-CCITT hash value for binary data, specifically using the CRC-HQX standard.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Python' + - 'binascii' + - 'hashing' + - 'checksum' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +The **`.crc_hqx()`** method is a function within Python's built-in `binascii` module used to compute a 16-bit Cyclic Redundancy Check (CRC) value. This specific implementation uses the parameters of the **CRC-HQX** standard (known for its use in the original Mac OS). + +Checksums are primarily used to detect errors in data transmission or storage, ensuring that the data received is identical to the data sent. + +## Syntax + +The method takes the binary data to be checked and an optional initial CRC value. + +```pseudo +binascii.crc_hqx(data, crc) +``` + +## Parameters + +* `data` (bytes-like object): The binary data for which the CRC value should be calculated. +* `crc` (integer): An optional 16-bit starting value for the checksum calculation. If omitted, the initial value is `0`. + +## Return Value + +Returns an integer representing the 16-bit CRC-HQX checksum of the input data. + +## Example + +This example demonstrates computing the checksum for a short byte string, both with and without an initial CRC value. + +```python +import binascii + +data = b"Codecademy Docs" +initial_crc = 0xAAAA # A common non-zero starting value + +# 1. Compute CRC with a starting value (0xAAAA) +crc_with_initial = binascii.crc_hqx(data, initial_crc) + +# 2. Compute CRC starting from 0 +crc_without_initial = binascii.crc_hqx(data, 0) + +print(f"Data: {data!r}") +print(f"CRC (with initial value 0xAAAA): 0x{crc_with_initial:04x}") +print(f"CRC (starting from 0): 0x{crc_without_initial:04x}") +``` + +**Output:** + +```shell +Data: b'Codecademy Docs' +CRC (with initial value 0xAAAA): 0x05f0 +CRC (starting from 0): 0xa663 +``` + +## Codebyte + +Use the Codebyte below to calculate the CRC-HQX checksum for your own byte string. + +```python +import binascii + +data_to_check = b"Python Contributor" + +# Calculate the CRC-HQX checksum starting from 0 +checksum = binascii.crc_hqx(data_to_check, 0) + +print(f"Checksum: 0x{checksum:04x}") +``` \ No newline at end of file From 583af05130ad29b6d7b47129f452812b34f5bdf0 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Wed, 5 Nov 2025 15:17:32 +0530 Subject: [PATCH 2/3] content changes --- .../binascii-module/crc-hqx/crc-hqx.md | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md b/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md index 9f49c675e15..40d72cde785 100644 --- a/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md +++ b/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md @@ -1,45 +1,43 @@ --- Title: '.crc_hqx()' -Description: 'Computes the CRC-CCITT hash value for binary data, specifically using the CRC-HQX standard.' +Description: 'Computes a 16-bit CRC (CRC-CCITT) checksum of binary data using the CRC-HQX algorithm.' Subjects: - 'Computer Science' - 'Data Science' Tags: - - 'Python' - - 'binascii' - - 'hashing' - - 'checksum' + - 'Algorithms' + - 'Functions' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -The **`.crc_hqx()`** method is a function within Python's built-in `binascii` module used to compute a 16-bit Cyclic Redundancy Check (CRC) value. This specific implementation uses the parameters of the **CRC-HQX** standard (known for its use in the original Mac OS). +The **`.crc_hqx()`** function in Python’s built-in `binascii` module computes a 16-bit Cyclic Redundancy Check (CRC) value using the CRC-HQX algorithm, commonly used in the original Mac OS. -Checksums are primarily used to detect errors in data transmission or storage, ensuring that the data received is identical to the data sent. +This checksum helps detect errors in data transmission or storage by verifying that the received data matches the original data. ## Syntax The method takes the binary data to be checked and an optional initial CRC value. ```pseudo -binascii.crc_hqx(data, crc) +binascii.crc_hqx(data, value) ``` -## Parameters +**Parameters:** -* `data` (bytes-like object): The binary data for which the CRC value should be calculated. -* `crc` (integer): An optional 16-bit starting value for the checksum calculation. If omitted, the initial value is `0`. +- `data` (bytes-like object): The binary data for which the CRC value is computed. +- `value` (integer): An optional 16-bit starting value for the checksum calculation. If omitted, the initial value is `0`. -## Return Value +**Return value:** -Returns an integer representing the 16-bit CRC-HQX checksum of the input data. +Returns a 16-bit integer representing the computed CRC checksum of the input data, according to the CRC-HQX algorithm. ## Example -This example demonstrates computing the checksum for a short byte string, both with and without an initial CRC value. +In this example, the checksum is computed for a byte string, once with a non-zero starting value and once with an initial value of 0: -```python +```py import binascii data = b"Codecademy Docs" @@ -56,19 +54,19 @@ print(f"CRC (with initial value 0xAAAA): 0x{crc_with_initial:04x}") print(f"CRC (starting from 0): 0x{crc_without_initial:04x}") ``` -**Output:** +The output of this code is: ```shell Data: b'Codecademy Docs' -CRC (with initial value 0xAAAA): 0x05f0 -CRC (starting from 0): 0xa663 +CRC (with initial value 0xAAAA): 0x134c +CRC (starting from 0): 0x67ce ``` -## Codebyte +## Codebyte Example -Use the Codebyte below to calculate the CRC-HQX checksum for your own byte string. +This example below computes the CRC-HQX checksum for a byte string using a starting value of 0: -```python +```codebyte/python import binascii data_to_check = b"Python Contributor" @@ -77,4 +75,4 @@ data_to_check = b"Python Contributor" checksum = binascii.crc_hqx(data_to_check, 0) print(f"Checksum: 0x{checksum:04x}") -``` \ No newline at end of file +``` From 84afa81cc186333258a5e193df8c50c3dff3a26d Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Wed, 5 Nov 2025 21:48:30 +0530 Subject: [PATCH 3/3] Minor changes --- .../concepts/binascii-module/{ => terms}/crc-hqx/crc-hqx.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) rename content/python/concepts/binascii-module/{ => terms}/crc-hqx/crc-hqx.md (94%) diff --git a/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md b/content/python/concepts/binascii-module/terms/crc-hqx/crc-hqx.md similarity index 94% rename from content/python/concepts/binascii-module/crc-hqx/crc-hqx.md rename to content/python/concepts/binascii-module/terms/crc-hqx/crc-hqx.md index 40d72cde785..277ccd41119 100644 --- a/content/python/concepts/binascii-module/crc-hqx/crc-hqx.md +++ b/content/python/concepts/binascii-module/terms/crc-hqx/crc-hqx.md @@ -18,8 +18,6 @@ This checksum helps detect errors in data transmission or storage by verifying t ## Syntax -The method takes the binary data to be checked and an optional initial CRC value. - ```pseudo binascii.crc_hqx(data, value) ``` @@ -35,7 +33,7 @@ Returns a 16-bit integer representing the computed CRC checksum of the input dat ## Example -In this example, the checksum is computed for a byte string, once with a non-zero starting value and once with an initial value of 0: +In this example, the checksum is computed for a byte string, once with a non-zero starting value and once with an initial value of `0`: ```py import binascii @@ -64,7 +62,7 @@ CRC (starting from 0): 0x67ce ## Codebyte Example -This example below computes the CRC-HQX checksum for a byte string using a starting value of 0: +This example below computes the CRC-HQX checksum for a byte string using a starting value of `0`: ```codebyte/python import binascii