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!
-
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.
|