You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: 'Computes the CRC-32 checksum of binary data using a cyclic redundancy check algorithm.'
4
+
Subjects:
5
+
- 'Computer Science'
6
+
- 'Data Science'
7
+
Tags:
8
+
- 'Encoding'
9
+
- 'Error Handling'
10
+
- 'Functions'
11
+
CatalogContent:
12
+
- 'learn-python-3'
13
+
- 'paths/computer-science'
14
+
---
15
+
16
+
The **`.crc32()`** function computes a CRC-32 checksum of the given data using a cyclic redundancy check algorithm. It is commonly used to detect accidental changes in raw data.
17
+
18
+
## Syntax
19
+
20
+
```pseudo
21
+
binascii.crc32(data, value=0)
22
+
```
23
+
24
+
**Parameters:**
25
+
26
+
-`data`: A bytes-like object containing the binary data whose CRC-32 checksum is to be computed.
27
+
-`value` (optional): An initial CRC value. This can be used to compute cumulative CRCs across multiple data blocks. Default is `0`.
28
+
29
+
**Return value:**
30
+
31
+
Returns an integer representing the CRC-32 checksum of the input data.
32
+
33
+
## Example
34
+
35
+
In this example, the CRC-32 checksum of a single string of binary data is computed:
36
+
37
+
```py
38
+
import binascii
39
+
40
+
# Create binary data
41
+
binary_data =b"hello world"
42
+
43
+
# Compute the CRC-32 checksum
44
+
checksum = binascii.crc32(binary_data)
45
+
46
+
print(checksum)
47
+
```
48
+
49
+
This produces the following output :
50
+
51
+
```shell
52
+
222957957
53
+
```
54
+
55
+
The output value is an unsigned 32-bit integer representing the checksum of the input data.
56
+
57
+
## Codebyte Example
58
+
59
+
In this example, the CRC-32 checksum is computed incrementally for multiple chunks of data, simulating a real-world file integrity check:
0 commit comments