Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: XOR'ing calculate a hex checksum

by halley (Prior)
on Jan 28, 2008 at 17:32 UTC ( #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 ]

Comment on Re: XOR'ing calculate a hex checksum
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-11-29 22:24 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls