http://www.perlmonks.org?node_id=1205629

holandes777 has asked for the wisdom of the Perl Monks concerning the following question:

Lift the veil of ignorance from my eyes

I am trying to follow am LRC computation (Longitudinal CRC computation) and have hit a bump

# Calculating the exclusive or of "202005" # V= X’32’ .XOR. X’30’ .XOR. X’32’ .XOR. X’30’ .XOR. X’30’ .XOR. X’35’ + = X’05’ my $command = '202005'; print "$command length=" . length($command) . "\n"; my $result = substr($command,0,1); for (my $i=1; $i<length($command); $i++) { my $c = substr($command,$i,1); print "$i) " . sprintf("%02X ", ord($result)) . " xor ". sprintf(" +%02X ", ord($c)); $result = $result ^ $c; print " gives " . sprintf("%02X ", ord($result)) . "\n"; } print sprintf("%02X ", ord($result)) . "\n"; if ( $result == "\x05" ) { print ":-)\n"; } else { print ":-(\n"; } print "====\n"; # THIS IS WHERE THE PROBLEM BEGINS: # Divide by X’10: # Y = INT ( X’05’ / X’10’ ) = X’00’ my $dividend = $result; my $divisor = "\x10"; my $result2; #$result2 = int($dividend/$divisor); #print sprintf("%02X ", ord($result2)) . "\n"; # results in Illegal division by zero at kk.pl line 22. # and this results in character zero, not NUL: $result2 = int(ord($dividend)/ord($divisor)); print sprintf("%02X ", ord($result2)) . "\n";

What concept did I miss? Thank you.

It has been pointed out I was noyt clear as to what I needed, and it is true! So allow me to clarify:

The result of the xor-ing is correct according to the API doc: they expect X'05' and if you run the code we have a display of 05 which is 0x05. It is the next step, where we divide this 0x05 result by X'10' (0x10). The code says:<\p> $result2 = int($dividend/$divisor);

what I expect is 5/16 converted to an int which is the NUL characted (0x00) which the API show as X'00'. The result I AM getting is 30 (0x30 or the ascii charated zero). This is where I need your help, on the last statement.