sprintf or pack

Discussion in 'Perl Misc' started by sonet, Jan 30, 2007.

  1. sonet

    sonet Guest

    How to use pack or sprintf do the same thing?

    $b='A';
    $a=ord($b);
    print int($a/16) . ($a % 16) ;
    sonet, Jan 30, 2007
    #1
    1. Advertising

  2. sonet

    Paul Lalli Guest

    On Jan 30, 7:33 am, "sonet" <> wrote:
    > How to use pack or sprintf do the same thing?
    >
    > $b='A';
    > $a=ord($b);
    > print int($a/16) . ($a % 16) ;


    printf "%x", $a;

    Paul Lalli
    Paul Lalli, Jan 30, 2007
    #2
    1. Advertising

  3. sonet

    Mirco Wahab Guest

    Paul Lalli wrote:
    > On Jan 30, 7:33 am, "sonet" <> wrote:
    >> How to use pack or sprintf do the same thing?
    >> $b='A';
    >> $a=ord($b);
    >> print int($a/16) . ($a % 16) ;

    >
    > printf "%x", $a;


    other TIMTOWTDIs

    print unpack "H*", 'A';

    or (non portable)

    print unpack("H", 'A')
    .unpack("h", 'A');

    or

    print +(ord('A')>>4)
    .(ord('A')&15);

    etc.

    M.
    Mirco Wahab, Jan 30, 2007
    #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. shea martin

    sprintf

    shea martin, Sep 2, 2004, in forum: Java
    Replies:
    5
    Views:
    3,585
    shea martin
    Sep 3, 2004
  2. Pep
    Replies:
    5
    Views:
    4,050
  3. CJ
    Replies:
    1
    Views:
    1,314
    Davlet Panech
    Oct 28, 2003
  4. Tim Jones
    Replies:
    0
    Views:
    371
    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:
    125
    Ilmari Karonen
    Jun 23, 2005
Loading...

Share This Page