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

Re: Binary value of string

by zek152 (Pilgrim)
on Jul 11, 2011 at 19:05 UTC ( [id://913754]=note: print w/replies, xml ) Need Help??


in reply to Binary value of string

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-03-19 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found