in reply to Binary value of string
$sum = 0; $sum += $_ for unpack 'C*', "This is a string to change to binary"; print $sum;; 3325
Or
print unpack '%32C*', "This is a string to change to binary";; 3325
But the result will be modulo 2**32 (assuming it ever gets that high; which won;t happen until your strings are at least 16 million characters long.
If that was a concern, on a perl with 64-bit ints you can do:
print unpack '%64C*', "This is a string to change to binary";; 3325
Which will handle strings to at least 72057594037927936 bytes, which should be enough to be going on with :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Binary value of string
by Yary (Pilgrim) on Jul 11, 2011 at 19:35 UTC | |
by BrowserUk (Patriarch) on Jul 11, 2011 at 20:07 UTC | |
by ikegami (Patriarch) on Jul 11, 2011 at 21:20 UTC | |
by BrowserUk (Patriarch) on Jul 11, 2011 at 22:27 UTC |