http://www.perlmonks.org?node_id=992924


in reply to array of binaries to hex conversion

$ perl -le' my @rand1 = qw( 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 ); sub stringdecimal { return unpack("N", pack("B32", substr("0" x 32 . shift, -32))); } sub arraystring { my $string = join("", @_); return $string; } my $bin = arraystring (@rand1); my $dec = stringdecimal($bin); my $hex = sprintf("0x%x", $dec); print $hex; ' 0x2abb1 $ perl -le' my @rand1 = qw( 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 ); my $hex = sprintf "0x%x", oct "0b" . join "", @rand1; print $hex; ' 0x2abb1