#!/usr/bin/perl -l

# Convert a binary number (in this case, the ASCII values of 'E',
# 'F', 'G', and 'H', concatenated) into a bit vector:
#
$str = pack('B*', '01000101010001100100011101001000');

# Print the "string value" of $str.
#
print $str;                        #  prints EFGH

# Print the individual bits of $str: 10100010011000101110001000010010,
# which is the original binary string with each byte reversed.
#
foreach (0..31) { print vec($str, $_, 1) }

# Another way to convert a number into a bit vector.
# Note that this number is so big
# (5 characters * 8 bits/character = 40 bits)
# that it can't fit into a regular 32-bit integer.
#
$str = join('', unpack('B*', 'k%n]{'));

print $str;

# Convert a hexadecimal number to a bit vector:
#
$str = pack('H*', '3a2d29');       #  $str is now :-)

print $str;

# Convert a string to hexadecimal.  
# This number can't even fit into a 64-bit integer, 
# since it's 12 characters and therefore 96 bits.  

$hex = join('',unpack('H*','-algorithms-')); # 2d616c676f726974686d732d

print $hex;
