Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^6: ECC computation

by LanX (Saint)
on Jan 05, 2020 at 22:24 UTC ( [id://11111010]=note: print w/replies, xml ) Need Help??


in reply to Re^5: ECC computation
in thread ECC computation

> more than five times faster than my previous one:

Cool, it works?

> Yes, I'm not a frequent user of pack and unpack

neither am I, so I left it to you ... ;-)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^7:ECC computation
by choroba (Cardinal) on Jan 05, 2020 at 22:28 UTC
    > Cool, it works?

    It works the same way as my previous solutions. The specification was vague and there were no test cases, so I'm waiting for the OP to confirm its correctness.

    Update: BTW, have you noticed the id of your node (as well as this one) is a possible output?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      > BTW, have you noticed the id of your node (as well as this one) is a possible output?

      Now that you mention it...

      we should keep replying ... but only as long as error correction fits ;-)

      update

      [id://11111012] damn!

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Thanks, it is quite fast, but doesn't seem to match parity I have. My specification was perhaps ambiguous.

      I tried online parity calculator from here.

      For example, I entered my hex data 7EA0F6A0 and clicked 'use extra parity bit'. Then the hamming code it generated is 0111111 (The CGI code for this is such that it puts the code in LSB bits for some reason).

      With the Perl code, I see ECC as 0110110.

        OK, so just reverse all the masks and store the bits in reverse order into each @r:
        my @masks = qw( 01010110101010101010110101011011 10011011001100110011011001101101 11100011110000111100011110001110 00000011111111000000011111110000 00000011111111111111100000000000 11111100000000000000000000000000 11111111111111111111111111111111 ); sub ecc { my ($hex) = @_; my $d = unpack 'B32', pack 'H8', $hex; my @r; unshift @r, unpack '%1B*', $_ & $d for @masks; $r[0] = unpack '%1B*', $r[0] . join "", @r[ 1 .. $#r ]; return join "", @r }
        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found