equivalent of php function decbin

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default equivalent of php function decbin

    Perl-php gurus,

    I need to port a php program to Perl and wonder the equivalent of
    decbin function in PHP could be the following:

    sub decbin {
    my $num=shift;
    my $str = unpack("b*",pack("N",$num));
    return $str;
    }

    Regards
    Thomas.
    Thomas Theakanath Guest

  2. Similar Questions and Discussions

    1. "between" function equivalent in Perl?
      Hello All- I'm attempting to extract a substring of characters from an alphanumeric text string. I've read a lot of Perl documentation on the...
    2. PHP equivalent to MOD
      Hi, I need to see if a number is divisible by 2. I don't see the math function "mod" in my PHP Functions reference manual. Is there another way...
    3. php equivalent of CGI.pm
      I'm translating several old cgi scripts (that use CGI.pm) to php. CGI.pm has a series of conventient function calls for generating HTML code on the...
    4. ACT! Equivalent for Mac?
      Does anyone know if there is a Macintosh program whose features are roughly equivalent? This PC software runs on VPC, but is fairly sluggish....
    5. What is equivalent to instrRev() function of VB-6 in Sql 2K ?
      What is equivalent to instrRev() function of VB-6 in Sql 2K ? For example: Retrieving last dot position from 2.2.5.4.3 which is : 8 Best...
  3. #2

    Default Re: equivalent of php function decbin

    * Thomas Theakanath <thomastk@hotmail.com>:
    > I need to port a php program to Perl and wonder the
    > equivalent of decbin function in PHP could be the
    > following:
    perlfaq4 - "How do I convert between numeric representations/bases/radixes?"

    [url]http://faq.perl.org/perlfaq4.html#How_do_I_convert_bet[/url]


    The FAQ is worth a good read through so you have an idea of
    what is in it.


    cheers,
    --
    Iain.
    Iain Truskett Guest

  4. #3

    Default Re: equivalent of php function decbin

    Thanks much. As usual, there are multiple ways to do this, per the
    FAQ, using sprintf and Vector. My corrected routine would be the
    following:
    sub decbin {
    my $num=shift;
    my $str = unpack("B*",pack("N",$num));
    return $str;
    }

    Thomas.
    Thomas Theakanath Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139