perl/c++ calculation

C

Cab Colino

hi,

i try to implement a calculation that i got in c++
in my perl project.


example:

c++:
unsigned char byte[] = "a";
int crc32 = 0xFFFFFFFF;
crc32 = ((crc32) >> 8) ^ array[(chr[0]) ^ ((crc32) & 0x000000FF)];

crc32 = -397917764

perl:
$crc32 = 0xFFFFFFFF;
$byte = "a";
$byte = unpack("C",$byte);
$crc32 = (($crc32) >> 8) ^ $array[($byte) ^ (($crc32) & 0x000000FF)];

$crc32 = 390611388


if you can see, the problem is that i get different results in the two
callclations. any suggestions why?

i would be graceful for any suggest.

cya

cab
 
A

Arndt Jonasson

i try to implement a calculation that i got in c++
in my perl project.


example:

c++:
unsigned char byte[] = "a";
int crc32 = 0xFFFFFFFF;
crc32 = ((crc32) >> 8) ^ array[(chr[0]) ^ ((crc32) & 0x000000FF)];

crc32 = -397917764

perl:
$crc32 = 0xFFFFFFFF;
$byte = "a";
$byte = unpack("C",$byte);
$crc32 = (($crc32) >> 8) ^ $array[($byte) ^ (($crc32) & 0x000000FF)];

$crc32 = 390611388


if you can see, the problem is that i get different results in the two
callclations. any suggestions why?

i would be graceful for any suggest.

I think you want to use 'byte' in the C++ code, and not 'chr[0]'. It's
a good habit to only paste code that you actually ran. And the
contents of the two arrays could be interesting too. But the problem
is probably this:

% perl -e 'printf("%d\n", 0xFFFFFFFF >> 8)'
16777215

0xffffffff >> 8 in C++, on the other hand, is sign extended, and remains
0xffffffff.
 
C

Cab Colino

yeah, your right thanks.
i've tried to simplfy the code, and i was sure that the
array isnt the problem.

thanks a lot

cab

....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top