How to build CRC32 table for Ogg?
From this answer I adapted the code below:
function _makeCRCTable() {
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i;
for (let j = 8; j--;) {
char = char & 1 ? 3988292384 ^ char >>> 1 : char >>> 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
This code generates table as here, but for Ogg I need another table - as here.
From Ogg documentation:
32 bit CRC value (direct algorithm, initial val and final XOR = 0,
generator polynomial=0x04c11db7)
parseInt('04c11db7', 16)
return 79764919
- I tried this polynomial but resulting table is not correct.
I am new to the CRC field, as I found there are a few variations of CRC32 algorithm.
javascript crc ogg crc32
add a comment |
From this answer I adapted the code below:
function _makeCRCTable() {
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i;
for (let j = 8; j--;) {
char = char & 1 ? 3988292384 ^ char >>> 1 : char >>> 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
This code generates table as here, but for Ogg I need another table - as here.
From Ogg documentation:
32 bit CRC value (direct algorithm, initial val and final XOR = 0,
generator polynomial=0x04c11db7)
parseInt('04c11db7', 16)
return 79764919
- I tried this polynomial but resulting table is not correct.
I am new to the CRC field, as I found there are a few variations of CRC32 algorithm.
javascript crc ogg crc32
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01
add a comment |
From this answer I adapted the code below:
function _makeCRCTable() {
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i;
for (let j = 8; j--;) {
char = char & 1 ? 3988292384 ^ char >>> 1 : char >>> 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
This code generates table as here, but for Ogg I need another table - as here.
From Ogg documentation:
32 bit CRC value (direct algorithm, initial val and final XOR = 0,
generator polynomial=0x04c11db7)
parseInt('04c11db7', 16)
return 79764919
- I tried this polynomial but resulting table is not correct.
I am new to the CRC field, as I found there are a few variations of CRC32 algorithm.
javascript crc ogg crc32
From this answer I adapted the code below:
function _makeCRCTable() {
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i;
for (let j = 8; j--;) {
char = char & 1 ? 3988292384 ^ char >>> 1 : char >>> 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
This code generates table as here, but for Ogg I need another table - as here.
From Ogg documentation:
32 bit CRC value (direct algorithm, initial val and final XOR = 0,
generator polynomial=0x04c11db7)
parseInt('04c11db7', 16)
return 79764919
- I tried this polynomial but resulting table is not correct.
I am new to the CRC field, as I found there are a few variations of CRC32 algorithm.
javascript crc ogg crc32
javascript crc ogg crc32
edited Nov 24 at 6:34
rcgldr
15.1k31333
15.1k31333
asked Nov 22 at 22:51
Vitaly Zdanevich
2,36632136
2,36632136
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01
add a comment |
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure of javascript precedence, but the xor needs to occur after the shift:
char = char & 1 ? 3988292384 ^ (char >>> 1) : char >>> 1;
However the first table you show seems correct, as table[128] = table[0x80] = 3988292384 = 0xEDB88320 which is 0x104c11db7 bit reversed, then shifted right one bit.
The second table you have is for a left shifting CRC, where table[1] = x04c11db7. In this case the inner loop would include something like this:
let char = i << 24;
for (let j = 8; j--;) {
char = char & 0x80000000 ? 0x04c11db7 ^ char << 1 : char << 1;
}
Example C code for comparison, generates crc for the patterns {0x01}, {0x01,0x00}, {0x01,0x00,0x00}, {0x01,0x00,0x00,0x00}.
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
uint32_t crctbl[256];
void gentbl(void)
{
uint32_t crc;
uint32_t b;
uint32_t c;
uint32_t i;
for(c = 0; c < 0x100; c++){
crc = c<<24;
for(i = 0; i < 8; i++){
b = crc>>31;
crc <<= 1;
crc ^= (0 - b) & 0x04c11db7;
}
crctbl[c] = crc;
}
}
uint32_t crc32(uint8_t * bfr, size_t size)
{
uint32_t crc = 0;
while(size--)
crc = (crc << 8) ^ crctbl[(crc >> 24)^*bfr++];
return(crc);
}
int main(int argc, char** argv)
{
uint32_t crc;
uint8_t bfr[4] = {0x01,0x00,0x00,0x00};
gentbl();
crc = crc32(bfr, 1); /* 0x04c11db7 */
printf("%08xn", crc);
crc = crc32(bfr, 2); /* 0xd219c1dc */
printf("%08xn", crc);
crc = crc32(bfr, 3); /* 0x01d8ac87 */
printf("%08xn", crc);
crc = crc32(bfr, 4); /* 0xdc6d9ab7 */
printf("%08xn", crc);
return(0);
}
For JS:
function _makeCRC32Table() {
const polynomial = 79764919;
const mask = 2147483648;
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i << 24;
for (let j = 8; j--;) {
char = char & mask ? polynomial ^ char << 1 : char << 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
How to use this table:
[1, 0].reduce((crc, byte) => crc << 8 >>> 0 ^ CRCTable[crc >>> 24 ^ byte], 0) >>> 0
Here we added >>> 0
that takes the module of the number - because there is no unsigned int in JS - JavaScript doesn't have integers. It only has double precision floating-point numbers.
Note that for Ogg you must set generated CRC in the reverse order.
Thank you, I tried your code and my table now is0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is<<
and looks like XOR (^) already executed after the shift - according to the message fromEslint
and I checked with and without brackets - result is the same.
– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.i
needs to go into the upper bits of the crc before it is cycled.
– rcgldr
Nov 23 at 8:13
Thank you!0x04c11db7
is called polynomial, but what it0x80000000
? I just want to use named variables in lieu of this magic numbers.
– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438815%2fhow-to-build-crc32-table-for-ogg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure of javascript precedence, but the xor needs to occur after the shift:
char = char & 1 ? 3988292384 ^ (char >>> 1) : char >>> 1;
However the first table you show seems correct, as table[128] = table[0x80] = 3988292384 = 0xEDB88320 which is 0x104c11db7 bit reversed, then shifted right one bit.
The second table you have is for a left shifting CRC, where table[1] = x04c11db7. In this case the inner loop would include something like this:
let char = i << 24;
for (let j = 8; j--;) {
char = char & 0x80000000 ? 0x04c11db7 ^ char << 1 : char << 1;
}
Example C code for comparison, generates crc for the patterns {0x01}, {0x01,0x00}, {0x01,0x00,0x00}, {0x01,0x00,0x00,0x00}.
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
uint32_t crctbl[256];
void gentbl(void)
{
uint32_t crc;
uint32_t b;
uint32_t c;
uint32_t i;
for(c = 0; c < 0x100; c++){
crc = c<<24;
for(i = 0; i < 8; i++){
b = crc>>31;
crc <<= 1;
crc ^= (0 - b) & 0x04c11db7;
}
crctbl[c] = crc;
}
}
uint32_t crc32(uint8_t * bfr, size_t size)
{
uint32_t crc = 0;
while(size--)
crc = (crc << 8) ^ crctbl[(crc >> 24)^*bfr++];
return(crc);
}
int main(int argc, char** argv)
{
uint32_t crc;
uint8_t bfr[4] = {0x01,0x00,0x00,0x00};
gentbl();
crc = crc32(bfr, 1); /* 0x04c11db7 */
printf("%08xn", crc);
crc = crc32(bfr, 2); /* 0xd219c1dc */
printf("%08xn", crc);
crc = crc32(bfr, 3); /* 0x01d8ac87 */
printf("%08xn", crc);
crc = crc32(bfr, 4); /* 0xdc6d9ab7 */
printf("%08xn", crc);
return(0);
}
For JS:
function _makeCRC32Table() {
const polynomial = 79764919;
const mask = 2147483648;
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i << 24;
for (let j = 8; j--;) {
char = char & mask ? polynomial ^ char << 1 : char << 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
How to use this table:
[1, 0].reduce((crc, byte) => crc << 8 >>> 0 ^ CRCTable[crc >>> 24 ^ byte], 0) >>> 0
Here we added >>> 0
that takes the module of the number - because there is no unsigned int in JS - JavaScript doesn't have integers. It only has double precision floating-point numbers.
Note that for Ogg you must set generated CRC in the reverse order.
Thank you, I tried your code and my table now is0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is<<
and looks like XOR (^) already executed after the shift - according to the message fromEslint
and I checked with and without brackets - result is the same.
– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.i
needs to go into the upper bits of the crc before it is cycled.
– rcgldr
Nov 23 at 8:13
Thank you!0x04c11db7
is called polynomial, but what it0x80000000
? I just want to use named variables in lieu of this magic numbers.
– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
|
show 3 more comments
I'm not sure of javascript precedence, but the xor needs to occur after the shift:
char = char & 1 ? 3988292384 ^ (char >>> 1) : char >>> 1;
However the first table you show seems correct, as table[128] = table[0x80] = 3988292384 = 0xEDB88320 which is 0x104c11db7 bit reversed, then shifted right one bit.
The second table you have is for a left shifting CRC, where table[1] = x04c11db7. In this case the inner loop would include something like this:
let char = i << 24;
for (let j = 8; j--;) {
char = char & 0x80000000 ? 0x04c11db7 ^ char << 1 : char << 1;
}
Example C code for comparison, generates crc for the patterns {0x01}, {0x01,0x00}, {0x01,0x00,0x00}, {0x01,0x00,0x00,0x00}.
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
uint32_t crctbl[256];
void gentbl(void)
{
uint32_t crc;
uint32_t b;
uint32_t c;
uint32_t i;
for(c = 0; c < 0x100; c++){
crc = c<<24;
for(i = 0; i < 8; i++){
b = crc>>31;
crc <<= 1;
crc ^= (0 - b) & 0x04c11db7;
}
crctbl[c] = crc;
}
}
uint32_t crc32(uint8_t * bfr, size_t size)
{
uint32_t crc = 0;
while(size--)
crc = (crc << 8) ^ crctbl[(crc >> 24)^*bfr++];
return(crc);
}
int main(int argc, char** argv)
{
uint32_t crc;
uint8_t bfr[4] = {0x01,0x00,0x00,0x00};
gentbl();
crc = crc32(bfr, 1); /* 0x04c11db7 */
printf("%08xn", crc);
crc = crc32(bfr, 2); /* 0xd219c1dc */
printf("%08xn", crc);
crc = crc32(bfr, 3); /* 0x01d8ac87 */
printf("%08xn", crc);
crc = crc32(bfr, 4); /* 0xdc6d9ab7 */
printf("%08xn", crc);
return(0);
}
For JS:
function _makeCRC32Table() {
const polynomial = 79764919;
const mask = 2147483648;
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i << 24;
for (let j = 8; j--;) {
char = char & mask ? polynomial ^ char << 1 : char << 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
How to use this table:
[1, 0].reduce((crc, byte) => crc << 8 >>> 0 ^ CRCTable[crc >>> 24 ^ byte], 0) >>> 0
Here we added >>> 0
that takes the module of the number - because there is no unsigned int in JS - JavaScript doesn't have integers. It only has double precision floating-point numbers.
Note that for Ogg you must set generated CRC in the reverse order.
Thank you, I tried your code and my table now is0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is<<
and looks like XOR (^) already executed after the shift - according to the message fromEslint
and I checked with and without brackets - result is the same.
– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.i
needs to go into the upper bits of the crc before it is cycled.
– rcgldr
Nov 23 at 8:13
Thank you!0x04c11db7
is called polynomial, but what it0x80000000
? I just want to use named variables in lieu of this magic numbers.
– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
|
show 3 more comments
I'm not sure of javascript precedence, but the xor needs to occur after the shift:
char = char & 1 ? 3988292384 ^ (char >>> 1) : char >>> 1;
However the first table you show seems correct, as table[128] = table[0x80] = 3988292384 = 0xEDB88320 which is 0x104c11db7 bit reversed, then shifted right one bit.
The second table you have is for a left shifting CRC, where table[1] = x04c11db7. In this case the inner loop would include something like this:
let char = i << 24;
for (let j = 8; j--;) {
char = char & 0x80000000 ? 0x04c11db7 ^ char << 1 : char << 1;
}
Example C code for comparison, generates crc for the patterns {0x01}, {0x01,0x00}, {0x01,0x00,0x00}, {0x01,0x00,0x00,0x00}.
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
uint32_t crctbl[256];
void gentbl(void)
{
uint32_t crc;
uint32_t b;
uint32_t c;
uint32_t i;
for(c = 0; c < 0x100; c++){
crc = c<<24;
for(i = 0; i < 8; i++){
b = crc>>31;
crc <<= 1;
crc ^= (0 - b) & 0x04c11db7;
}
crctbl[c] = crc;
}
}
uint32_t crc32(uint8_t * bfr, size_t size)
{
uint32_t crc = 0;
while(size--)
crc = (crc << 8) ^ crctbl[(crc >> 24)^*bfr++];
return(crc);
}
int main(int argc, char** argv)
{
uint32_t crc;
uint8_t bfr[4] = {0x01,0x00,0x00,0x00};
gentbl();
crc = crc32(bfr, 1); /* 0x04c11db7 */
printf("%08xn", crc);
crc = crc32(bfr, 2); /* 0xd219c1dc */
printf("%08xn", crc);
crc = crc32(bfr, 3); /* 0x01d8ac87 */
printf("%08xn", crc);
crc = crc32(bfr, 4); /* 0xdc6d9ab7 */
printf("%08xn", crc);
return(0);
}
For JS:
function _makeCRC32Table() {
const polynomial = 79764919;
const mask = 2147483648;
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i << 24;
for (let j = 8; j--;) {
char = char & mask ? polynomial ^ char << 1 : char << 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
How to use this table:
[1, 0].reduce((crc, byte) => crc << 8 >>> 0 ^ CRCTable[crc >>> 24 ^ byte], 0) >>> 0
Here we added >>> 0
that takes the module of the number - because there is no unsigned int in JS - JavaScript doesn't have integers. It only has double precision floating-point numbers.
Note that for Ogg you must set generated CRC in the reverse order.
I'm not sure of javascript precedence, but the xor needs to occur after the shift:
char = char & 1 ? 3988292384 ^ (char >>> 1) : char >>> 1;
However the first table you show seems correct, as table[128] = table[0x80] = 3988292384 = 0xEDB88320 which is 0x104c11db7 bit reversed, then shifted right one bit.
The second table you have is for a left shifting CRC, where table[1] = x04c11db7. In this case the inner loop would include something like this:
let char = i << 24;
for (let j = 8; j--;) {
char = char & 0x80000000 ? 0x04c11db7 ^ char << 1 : char << 1;
}
Example C code for comparison, generates crc for the patterns {0x01}, {0x01,0x00}, {0x01,0x00,0x00}, {0x01,0x00,0x00,0x00}.
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
uint32_t crctbl[256];
void gentbl(void)
{
uint32_t crc;
uint32_t b;
uint32_t c;
uint32_t i;
for(c = 0; c < 0x100; c++){
crc = c<<24;
for(i = 0; i < 8; i++){
b = crc>>31;
crc <<= 1;
crc ^= (0 - b) & 0x04c11db7;
}
crctbl[c] = crc;
}
}
uint32_t crc32(uint8_t * bfr, size_t size)
{
uint32_t crc = 0;
while(size--)
crc = (crc << 8) ^ crctbl[(crc >> 24)^*bfr++];
return(crc);
}
int main(int argc, char** argv)
{
uint32_t crc;
uint8_t bfr[4] = {0x01,0x00,0x00,0x00};
gentbl();
crc = crc32(bfr, 1); /* 0x04c11db7 */
printf("%08xn", crc);
crc = crc32(bfr, 2); /* 0xd219c1dc */
printf("%08xn", crc);
crc = crc32(bfr, 3); /* 0x01d8ac87 */
printf("%08xn", crc);
crc = crc32(bfr, 4); /* 0xdc6d9ab7 */
printf("%08xn", crc);
return(0);
}
For JS:
function _makeCRC32Table() {
const polynomial = 79764919;
const mask = 2147483648;
const CRCTable = new Uint32Array(256);
for (let i = 256; i--;) {
let char = i << 24;
for (let j = 8; j--;) {
char = char & mask ? polynomial ^ char << 1 : char << 1;
}
CRCTable[i] = char;
}
return CRCTable;
}
How to use this table:
[1, 0].reduce((crc, byte) => crc << 8 >>> 0 ^ CRCTable[crc >>> 24 ^ byte], 0) >>> 0
Here we added >>> 0
that takes the module of the number - because there is no unsigned int in JS - JavaScript doesn't have integers. It only has double precision floating-point numbers.
Note that for Ogg you must set generated CRC in the reverse order.
edited Nov 27 at 11:07
Vitaly Zdanevich
2,36632136
2,36632136
answered Nov 23 at 7:06
rcgldr
15.1k31333
15.1k31333
Thank you, I tried your code and my table now is0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is<<
and looks like XOR (^) already executed after the shift - according to the message fromEslint
and I checked with and without brackets - result is the same.
– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.i
needs to go into the upper bits of the crc before it is cycled.
– rcgldr
Nov 23 at 8:13
Thank you!0x04c11db7
is called polynomial, but what it0x80000000
? I just want to use named variables in lieu of this magic numbers.
– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
|
show 3 more comments
Thank you, I tried your code and my table now is0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is<<
and looks like XOR (^) already executed after the shift - according to the message fromEslint
and I checked with and without brackets - result is the same.
– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.i
needs to go into the upper bits of the crc before it is cycled.
– rcgldr
Nov 23 at 8:13
Thank you!0x04c11db7
is called polynomial, but what it0x80000000
? I just want to use named variables in lieu of this magic numbers.
– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
Thank you, I tried your code and my table now is
0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is <<
and looks like XOR (^) already executed after the shift - according to the message from Eslint
and I checked with and without brackets - result is the same.– Vitaly Zdanevich
Nov 23 at 7:52
Thank you, I tried your code and my table now is
0 256 512 768 1024
in decimal numbers, looks like this is not correct. Anything else I can try? Also, just FYI - in JS left shift is <<
and looks like XOR (^) already executed after the shift - according to the message from Eslint
and I checked with and without brackets - result is the same.– Vitaly Zdanevich
Nov 23 at 7:52
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.
i
needs to go into the upper bits of the crc before it is cycled.– rcgldr
Nov 23 at 8:13
@VitalyZdanevich - I didn't include enough of the code. I updated my answer.
i
needs to go into the upper bits of the crc before it is cycled.– rcgldr
Nov 23 at 8:13
Thank you!
0x04c11db7
is called polynomial, but what it 0x80000000
? I just want to use named variables in lieu of this magic numbers.– Vitaly Zdanevich
Nov 23 at 11:01
Thank you!
0x04c11db7
is called polynomial, but what it 0x80000000
? I just want to use named variables in lieu of this magic numbers.– Vitaly Zdanevich
Nov 23 at 11:01
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
@VitalyZdanevich - 0x80000000 is the mask for most significant bit which is checked before doing the left shift. If it is 1 before the left shift, then after the left shift the crc is xor'ed with 0x04c11db7. This is simulating a divide by 0x104c11db7, which is 33 bits. If this was doing using 64 bit integers, you could shift left first, then check for (crc & 0x100000000) and if it's not zero, then xor with 0x104c11db7.
– rcgldr
Nov 23 at 11:21
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
Thank you, and another question - the next part of CRC32 algorithm that uses this table in always the same in all CRC variants? For example this one is correct?
– Vitaly Zdanevich
Nov 23 at 11:57
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438815%2fhow-to-build-crc32-table-for-ogg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do you need a function that procedurally generates the table when you could just copy and paste that one?
– Patrick Roberts
Nov 22 at 22:57
I think that this is more secure to generate table - against accidental changing of some value - with will lead to a bad situation when CRC32 will correct for 99% of cases.
– Vitaly Zdanevich
Nov 22 at 23:01