Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: CRC 16

by BrowserUk (Pope)
on Oct 08, 2012 at 08:21 UTC ( #997766=note: print w/replies, xml ) Need Help??

in reply to CRC 16

I can't see how 0x8404 is the 'reverse' of 0x1021 by any stretch of my imagination,(*)

but a simple brute force conversion yields:

#! perl -slw use strict; sub crc16 { use constant POLY => 0x8408; my $crc = 0; for my $c ( unpack 'C*', $_[0] ) { $crc ^= $c; for my $b ( 0 .. 7 ) { my $carry = $crc & 1; $crc >>= 1; if( $carry ) { $crc ^= POLY; } } } return $crc; } my $data = "\x64\x01"; printf "crc: %04x\n", crc16( $data ); __END__ C:\test> crc: 13bc

Which works for the (inadequate, single) sample data.

(* 0x1021 -> 0001_0000_0010_0001 bitwise reversed -> 1000_0100_0000_1000 -> 0x8408 )

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997766]
marto waves
[Corion]: Hi marto, Discipulus, choroba!
[Corion]: Seems like I chose just the right day to do a half-day recovery yesterday. Today it's snowing again, instead of the sun shining, so that's a good day to be at the office again ;)
[Discipulus]: good morning folks!

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2018-03-22 09:13 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (273 votes). Check out past polls.