try:
#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1181779 use strict; use warnings; sub convert { unpack('H*', shift() =~ tr/cd/qr/r) =~ tr/1267/0101/r; } for ( qw( abcd dcba abab cdcd abba caab ) ) { print "$_ -> ", convert($_); }
prints:
abcd -> 00011011 dcba -> 11100100 abab -> 00010001 cdcd -> 10111011 abba -> 00010100 caab -> 10000001
In reply to Re: convert each character of a string to number
by tybalt89
in thread convert each character of a string to number
by Lowry76
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |