Comments (3)
Thank you, I did something similar you provided, but it would be great to have additional function like CRC32.int or CRC32.hex to calculate CRC without extra code.
How did you get that CRC result 0x0AAFD11A?
You are right, the result should be 0xe9fc314b
it was my mistake.
from js-crc32.
additional function like CRC32.int or CRC32.hex to calculate CRC without extra code
C'mon, splitting number into 4 bytes isn't worth any library support, and calculating 32-bit crc from 32-bit number does not seem to be very common use case.
from js-crc32.
CRC32.buf
can take an array of bytes and CRC32.bstr
can take a binary string. Both return a signed 32-bit integer that you can convert to hex through unsigned conversion >>>0
and toString(16)
.
To convert the 32-bit number to bytes you can either unwind the bytes manually or use a Uint32Array:
var num = 0x200031E0;
/* Uint8Array */
var ua = new Uint8Array((new Uint32Array([num])).buffer); // Uint8Array [ 224, 49, 0, 32 ]
(CRC32.buf(ua)>>>0).toString(16); // e9fc314b
/* Array of bytes */
var arr = [], n2 = num; for(var i = 0; i < 4; ++i, n2>>>=8) arr[i] = n2 & 0xFF; // arr = [ 224, 49, 0, 32 ]
(CRC32.buf(arr)>>>0).toString(16); // e9fc314b
/* Binary string */
var bstr = ""; for(i = 0, n2 = num; i < 4; ++i, n2>>>=8) bstr += String.fromCharCode(n2 & 0xFF); // bstr = '\xe0\x31\x00\x20'
(CRC32.bstr(bstr)>>>0).toString(16); // e9fc314b
The result is determined to be 0xe9fc314b
. How did you get that CRC result 0x0AAFD11A
?
from js-crc32.
Related Issues (17)
- Why never gives the same result than others crc32? HOT 1
- How can I get the hex value of CRC32 HOT 1
- CRC32 slower than MD5 HOT 1
- Incorrect CRC-32 number returned when String or BinaryString contains an integer HOT 1
- Support Castagnoli CRC32 HOT 4
- Implement Slice-by-16 fast CRC algorithm
- CRC32 function produces incorrect values by default HOT 2
- CRC sometimes returns negative value HOT 2
- Problem with big array of bytes that not can convert the CRC Value to unsigned integer HOT 1
- v1.2.3 not published to npm? HOT 1
- Result is a Signed 32bit value, is this known and wanted? HOT 2
- Incorrect crc returned for a surrogate character HOT 1
- Can this be used to generate unsigned ints? HOT 1
- null values HOT 1
- crc-32 not working for >5Gb file . Support for large files HOT 4
- buf() mishandles [3, 0, 0, 0, 0] HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-crc32.