Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I can't tell if you are using the right algorithm, but here my little implementation inside the debugger.

Please note

  • how I avoid operating on strings, except for input and output.
  • that it doesn't matter if the input numbers are shown in decimal or hex.

DB<96> x @input = map {ord} split //,'202005' # input ASCII values 0 50 1 48 2 50 3 48 4 48 5 53 DB<97> $result = 0 ; # neutral start DB<98> $result ^= $_ for @input ; # XOR all DB<99> p $result 5 DB<100> p $result2 = int( $result / 0x10 ) 0 DB<101> print "Input: "; printf "0x%x ",$_ for @input Input: 0x32 0x30 0x32 0x30 0x30 0x35 DB<102> printf "Output: 0x%x", $result2 Output: 0x0

NB: in case you adopt this code:

  • p and x are debugger commands for dumping results, please ignore them.
  • please declare the variables with my (debugger can't handle them)
  • one doesn't need to decompose a string for input
    DB<105> x @input = (0x32, 0x30, 0x32, 0x30, 0x30, 0x35) 0 50 1 48 2 50 3 48 4 48 5 53
  • If you want to operate on large sets of data consider using unpack and pack to initalize the input
HTH!

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery


In reply to Re: hexadecimal division by LanX
in thread hexadecimal division by holandes777

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found