Dharshana Eswaran wrote:

On 11/17/06, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:

The input is "31","59", "4C","15","53","DD","54","31"

The above input is represented as shown below:

00110001 01011001 01001100 00010101 01010011 11011101 01010100 00110001

The correction in the desired output is


0110001
0110010
0110001
0101010
0110001
0101010
0110111
0101010
0110001
0

This is the complete pattern output for the input array....

The output should have 7bits for each representation. That is 8th bit of the
1st byte is taken as the 0th bit of the next byte and 7th and 8th  of the
second bytes becomes the 0th and 1st of the third byte, next 6th,  7th,8th of
the third becomes 0th,1st,2nd of the fourth....And so on....

I hope the corrections would help you better.

Ah, I see. The bits are in the opposite order to what I assumed. The code below
produces the correct result. All I've changed is to use an unpack format of 'b'
instead of 'B' which delivers the bits in the reverse order. Then we can just
take chunks of seven bits at a time from the string as before, but have to
reverse each chunk back again before it displayed.

I hope this helps.

Rob



use strict;
use warnings;

my @hex = ("31","59", "4C","15","53","DD","54","31");
my $hex = join '', @hex;
my $binary = unpack 'b*', pack 'H*', $hex;

my @fields = $binary =~ /.{1,7}/g;
$_ = reverse foreach @fields;

print "$_\n" foreach @fields;

**OUTPUT

0110001
0110010
0110001
0101010
0110001
0101010
0110111
0101010
0110001
0


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to