How do I convert hexadecimal into decimal

Using perl's built in conversion of 0x notation:

    $int = 0xDEADBEEF;
    $dec = sprintf("%d", $int);
Using the hex function:

    $int = hex("DEADBEEF");
    $dec = sprintf("%d", $int);
Using pack:

    $int = unpack("N", pack("H8", substr("0" x 8 . "DEADBEEF", -8)));
    $dec = sprintf("%d", $int);
Using the CPAN module Bit::Vector:

    use Bit::Vector;
    $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
    $dec = $vec->to_Dec();


Back to perlfaq4