On 11/17/06, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
On 11/17/06, Rob Dixon <[EMAIL PROTECTED]> wrote: > > Dharshana Eswaran wrote: > > > > On 11/16/06, Rob Dixon <[EMAIL PROTECTED] > wrote: > >> > >>>> Dharshana Eswaran wrote: > >>>>> > >>>>> I am working on the code below: > >>>>> > >>>>> my @hex = ("14", "2a", "11", "83"); > >>>>> $hex_length = @hex; > >>>>> > >>>>> for($i=0; $i<$hex_length; $i++) { > >>>>> > >>>>> my $binary = unpack 'B*', pack 'H*', $hex[$i]; > >>>>> > >>>>> print "$binary\n\n"; > >> > >> Oh dear. It looks like you have an ealier version of Perl where > unpack has no > >> sub-templates, altthough I thought it had always been like that. Find > out > >> what version you are running (with perl -v) and consider upgrading. I > am > >> using v5.8.8 and bmost people use v5.8 or above. > >> > >> In the meantime, replace > >> > >> my @fields = unpack '(A7)*', $binary; > >> > >> with > >> > >> my @fields = $binary =~ /.{1,7}/g; > > > > > > my @fields = $binary =~ /.{7,1}/g; This works fine > > > > my @fields = $binary =~ /.{7,1}/g; Why does'nt this work? > > > > Coz i wanted the procedure to be reversed, that is if the input is > > "31","59", "4C","15","53" > > > I wanted the output to be > > > > 0110001 > > 0110010 > > 0110001 > > 0101010 > > 1110001 > > 01010 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
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.... The 1 and the 7 in the regex can't be exchanged as they are a minimum and > maximum number of characters to match. The pattern matches between one > and seven > of any character, and so splits the 40-character string into five blocks > of > seven characters and one of five. > > I don't understand what you mean about reversing the procedure I'm > afraid. > > "31","59","4C","15","53" > > is > > 00110001 01011001 01001100 00010101 01010011 > > in binary, and I can't see how to get to the bit patterns you give from > that, > although it starts off close enough. Your fourth pattern of seven bits, > for > instance, has three consecutive 1s in it, and that doesn't appear > anywhere in > the number sequence you gave. > > Are you sure the data you've posted is right? > > Rob I hope the corrections would help you better. Thanks and Regards, Dharshana -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> < http://learn.perl.org/first-response> > > >