pack problem?

Discussion in 'Perl Misc' started by Davy, Aug 28, 2006.

  1. Davy

    Davy Guest

    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
    Davy, Aug 28, 2006
    #1
    1. Advertising

  2. Davy

    DJ Stunks Guest

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


    it has already been written for you.

    perldoc -f sprintf

    -jp
    DJ Stunks, Aug 28, 2006
    #2
    1. Advertising

  3. ["Followup-To:" header set to comp.lang.perl.misc.]
    On 2006-08-28 03:17, Davy <> 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
    |_|_) | Sysadmin WSR | > ist?
    | | | | Was sonst wäre der Sinn des Erfindens?
    __/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
    Peter J. Holzer, Aug 28, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PL

    Help Service Pack 4 Problem

    PL, Jul 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    352
  2. AspDotNetDeveloper

    Service Pack 2 Problem

    AspDotNetDeveloper, Apr 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,628
  3. Sathish
    Replies:
    1
    Views:
    400
    Ken Cox [Microsoft MVP]
    Oct 16, 2004
  4. Tim Jones
    Replies:
    0
    Views:
    366
    Tim Jones
    Jan 31, 2004
  5. Alexander Farber

    pack 'C3U*' not same as pack 'C3(xC)*'

    Alexander Farber, Jun 23, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    120
    Ilmari Karonen
    Jun 23, 2005
Loading...

Share This Page