Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: XOR'ing calculate a hex checksum

by halley (Prior)
on Jan 28, 2008 at 17:32 UTC ( [id://664720]=note: print w/replies, xml ) Need Help??


in reply to XOR'ing to calculate a hex checksum

Don't do math in terms of digits or strings. Do math in terms of numbers. Digits are just a way of viewing numbers, they aren't numbers themselves.

You appear to be converting all your incoming bytes into hex before we even get to look at it in your checksum() routine, and then going through some painful conversion work to turn the pairs of hex digits back into bytes. I'm going to ignore that, and assume you have an array of @bytes instead.

my $total = 0; $total += $_ for @bytes; $check = ($total & 0xFF) ^ 0xFF;

Once you have your check value, then you can decide how to display it (if it needs displaying at all).

--
[ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://664720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found