为什么标准 Java 和 JavaScript 库会生成不同的 CRC-32 值?我如何获得相同的结果?

Why do the standard Java and JavaScript libraries generate different CRC-32 values? How do I get the same result?

为什么 JavaScript crc-32 库和 Java CRC32 class returning 的结果不同?我执行错了吗?

const CRC32 = require('crc-32')
const input = "3b67b67f-673b-4f23-a023-3756f513d707:19.63865368:6ace080f-6f47-44fa-86f8-c278f5bb6f07:2.34121407:42dda603-8a36-4200-826c-80714a40b470:0.923498:1301a851-b77e-489f-beb8-c2b4ef349a90:0.08:bf077871-5709-4a84-b3a9-22bfa8313fa2:0.00382495:6341cbef-bccc-43af-8927-31be3f3cd2e9:1.24039659:aeef18c5-457c-41ca-abda-3940b151e410:0.02821:42943143-bb81-4993-8788-df3c434bce89:0.09:787ef6da-48ce-4bb5-978a-b0fdd9ce223a:0.07:c3850c7b-d0fa-4c2a-8c67-0405bee185da:0.50443922:06429537-15e7-465c-aafa-f9974fb20b95:0.48535755:978d18ba-ffe7-48a3-9642-0de57b249383:0.1:59de5468-be8c-4d56-ad1e-3425914fc081:0.35722062:b6eea705-651b-40db-9b01-e535150ab0f3:0.00408603:6cc9440e-d86b-475d-986e-b9076104873a:1.80178:7711fc0e-dc02-431f-90b8-fde7cd762ce0:0.00402297:58397c47-5cac-424c-9b2b-7dc50c703f6f:0.08"
CRC32.str(input)

# Result: -1990607021
import java.util.zip.CRC32

val input = "3b67b67f-673b-4f23-a023-3756f513d707:19.63865368:6ace080f-6f47-44fa-86f8-c278f5bb6f07:2.34121407:42dda603-8a36-4200-826c-80714a40b470:0.923498:1301a851-b77e-489f-beb8-c2b4ef349a90:0.08:bf077871-5709-4a84-b3a9-22bfa8313fa2:0.00382495:6341cbef-bccc-43af-8927-31be3f3cd2e9:1.24039659:aeef18c5-457c-41ca-abda-3940b151e410:0.02821:42943143-bb81-4993-8788-df3c434bce89:0.09:787ef6da-48ce-4bb5-978a-b0fdd9ce223a:0.07:c3850c7b-d0fa-4c2a-8c67-0405bee185da:0.50443922:06429537-15e7-465c-aafa-f9974fb20b95:0.48535755:978d18ba-ffe7-48a3-9642-0de57b249383:0.1:59de5468-be8c-4d56-ad1e-3425914fc081:0.35722062:b6eea705-651b-40db-9b01-e535150ab0f3:0.00408603:6cc9440e-d86b-475d-986e-b9076104873a:1.80178:7711fc0e-dc02-431f-90b8-fde7cd762ce0:0.00402297:58397c47-5cac-424c-9b2b-7dc50c703f6f:0.08"
val crC32 = CRC32()
crC32.update(input.toByteArray(Charsets.UTF_8))
crC32.value

# Result 2304360275

如何使 Kotlin 函数 return 与 Java 脚本具有相同的值?

它们没有什么不同。它们都是 完全相同的 32 位值,在一种情况下解释为无符号 32 位整数,在另一种情况下解释为二进制补码有符号 32 位整数。

只需将 Java long 值转换为 int(int),您将获得带符号的解释。