Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I would advise you to look at a standard hashing algorithm (like sha1,sha2 or md5)

If you still want to do it yourself:

$string = "This is a string to split and sum"; @chars = split(//,$string); $sum = 0; for(@chars) { #ord returns the numeric value of the char printf"char = %s:bin = %8b:dec = %d\n",$_,ord,ord; $sum+=ord; } print "sum = $sum\n"; #OUTPUT #char = T:bin = 1010100:dec = 84 #char = h:bin = 1101000:dec = 104 #char = i:bin = 1101001:dec = 105 #char = s:bin = 1110011:dec = 115 #char = :bin = 100000:dec = 32 #char = i:bin = 1101001:dec = 105 #char = s:bin = 1110011:dec = 115 #char = :bin = 100000:dec = 32 #char = a:bin = 1100001:dec = 97 #char = :bin = 100000:dec = 32 #char = s:bin = 1110011:dec = 115 #char = t:bin = 1110100:dec = 116 #char = r:bin = 1110010:dec = 114 #char = i:bin = 1101001:dec = 105 #char = n:bin = 1101110:dec = 110 #char = g:bin = 1100111:dec = 103 #char = :bin = 100000:dec = 32 #char = t:bin = 1110100:dec = 116 #char = o:bin = 1101111:dec = 111 #char = :bin = 100000:dec = 32 #char = s:bin = 1110011:dec = 115 #char = p:bin = 1110000:dec = 112 #char = l:bin = 1101100:dec = 108 #char = i:bin = 1101001:dec = 105 #char = t:bin = 1110100:dec = 116 #char = :bin = 100000:dec = 32 #char = a:bin = 1100001:dec = 97 #char = n:bin = 1101110:dec = 110 #char = d:bin = 1100100:dec = 100 #char = :bin = 100000:dec = 32 #char = s:bin = 1110011:dec = 115 #char = u:bin = 1110101:dec = 117 #char = m:bin = 1101101:dec = 109 #sum = 3043

In reply to Re: Binary value of string by zek152
in thread Binary value of string by packetstormer

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 goofing around in the Monastery: (2)
    As of 2024-07-14 17:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.