You may want to chomp the line to remove the newline character.

After' my $line = $_;' add:
  chomp $line;

On Wed, Dec 9, 2009 at 10:16 PM, Majian <jian...@gmail.com> wrote:

> Hi ,all :
>
>  I'd like to convert  binary file  intohex ,  but when I use perl's built
> in functions I keep getting extra bits on the end.
>
> cat bin_file
> 00000000000000000000100001100010
> 00010000010100100001100001000010
>
> My perl script is the following :
>
> #!/usr/bin/perl
>
> use strict;
>
> while (<>){
>          my $line = $_;
>           my $hex = unpack ("H*", pack("B*", $line));
>           print "$hex\n";
> }
>
>
>
> But the result is :
>  0x0000086200
>  0x1052184200
>
>
> And  I  use the "unpack ("H*", pack("B32", $line)" and the result is :
>
>  0x00000862
>  0x10521842
>
> Why does it become that?
>
>
> Thanks in advance ~~
>

Reply via email to