Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-10-02 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (54 votes), past polls