You can use unpack.
Here is an example from MacOS X rather than macperl, but it should work the same way.
% perl -e 'print unpack("B*", chr(29)), "\n"' 00011101
note that in the context of unpack, values always seem to be treated as strings; that is
% perl -e 'print unpack("B*", 29), "\n"'
0011001000111001
prints the binary for '2' and '9'.
On Mar 4, 2005, at 6:30 AM, [EMAIL PROTECTED] wrote:
----------------------------------------------------------------------
From: Detlef Lindenthal <[EMAIL PROTECTED]>
Date: March 4, 2005 6:28:43 AM EST
To: macperl@perl.org
Subject: How can I display a number in dual representation, e.g. 29 --> 11101?
What would be the easiest way to display a number as dual / binary number?
For example: 29 is to be displayed as 11101.
In PHP this would work: <? printf ("%b", 29); ?>
but not so in Perl. Any idea?
Detlef Lindenthal