in reply to Re: Handling binary
in thread Handling binary

I missed the part about having to generate these strings, here you go:

#!/usr/bin/perl # http://perlmonks.org/?node_id=1141773 use strict; use warnings; my $answer = handlingbinary( "139686DA20C1" ); print "$answer\n"; print tofivebit( 'ANONYMOUS MONK' ), "\n"; print tofivebit( 'COLINWRAY' ), "\n"; sub handlingbinary { return join '', ('A'..'Z')[ map { oct "0b$_" } (unpack 'B*', pack 'H*', shift()) =~ /.{5}/g ] } sub tofivebit { uc unpack 'H*', pack 'B*', shift() =~ tr/A-Z//cdr =~ s/(.)/ sprintf "%05b", ord($1) - ord('A' +) /ger; }

Replies are listed 'Best First'.
Re^3: Handling binary
by G109B (Initiate) on Sep 14, 2015 at 09:30 UTC

    Many thanks to the three responders, and yes you got it right. The code snippets contain some very welcome insights into this (sometimes) irritating language - at least to an old (retired) C/C++ programmer.

    Why 5 bit ? - not my choice, not my firmware which requires it, but surely to conserve space. There is some 6 bit later in the string because they needed to include digits.

    Hex is a way of life for me.

    Colin