For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2006 > pack problem?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author pack problem?
Davy

2006-08-27, 9:57 pm

Hi all,

I want to write a dec data to bin data translator.
But I found the $dec_pack in the program don't print "A signed integer
value" as the pack manual said. Why? Thanks!

#------------------------------------------------
use strict;
use warnings;


my $dec = 1234;
my $bin;

$bin = dec2bin($dec);

print 'bin is ',$bin,"\n";

sub dec2bin {
my $dec_shift = shift;
print 'dec_shift is ',$dec_shift, "\n";

my $dec_pack = pack("i", $dec_shift);
print 'dec_pack ',$dec_pack, "\n";

return unpack('B32', $dec_pack);
}
#----------------------------------------------------

Best regards,
Davy

DJ Stunks

2006-08-27, 9:57 pm


Davy wrote:
> I want to write a dec data to bin data translator.


it has already been written for you.

perldoc -f sprintf

-jp

Peter J. Holzer

2006-08-28, 6:57 pm

["Followup-To:" header set to comp.lang.perl.misc.]
On 2006-08-28 03:17, Davy <zhushenli@gmail.com> wrote:
> I want to write a dec data to bin data translator.
> But I found the $dec_pack in the program don't print "A signed integer
> value" as the pack manual said. Why? Thanks!


Why do you think so?

hp


--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Symin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com