in reply to question of pack.

re: converting decimal to hex and oct -
use warnings; use strict; print "Please input a hex no. to convert to dec. :"; chomp (my $value = <STDIN>); print hex("$value"), "\n";
Just replace hex( ) with oct( ) for oct. For binary there is no bin( ), I was struggling with the same problem recently -

http://perlmonks.org/index.pl?node_id=591504

should find some answers there. PS - can someone please tell me the tags to make urls clickable in a post? Ta

Edit, sorry - just spotted that I got the conversion backwards in the code

Replies are listed 'Best First'.
Re^2: question of pack.
by liverpole (Monsignor) on Dec 26, 2006 at 14:53 UTC
    Hi thevoid,

    If you read the documentation, you'll see that oct is capable of conversion from binary.  It just requires putting a leading '0b' in front of the number.

    For example:

    use strict; use warnings; my $value = "0b101010"; printf "$value is %d decimal\n", oct($value);

    Not too long ago, I even wrote a submission about it, in which I admitted that I didn't know about this additional functionality of oct until much later in my Perl education.

    As for your other question, to make links clickable, you can do this:  [id://591504], which will appear like "Bitwise operators" in the rendered page.

    See Writeup Formatting Tips and Perl Monks Approved HTML tags for more information.

    Update:  Fixed a transcription typo.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Hi liverpole, thanks for the info.