[Israel.pm] hex conversion

Gaal Yahas gaal at forum2.org
Tue Feb 3 02:11:11 PST 2004

On Tue, Feb 03, 2004 at 11:20:57AM +0200, Prager, Mark wrote:
> I am still writing newbie Perl scripts.
> How can I convert a hex 4 digit val to a decimal easily.
> e.g.
> $hexval="1234";
> $decval= something($hexval); # should be 4660

Note also that if you know the value at compile time, you can use 0x
notation and a literal, as you would e.g. in C. This is a bit faster.

     $val = 0x1234;

You can also use octal this way (e.g. 0644), or binary (0b1101).

But there's no built-in way to translate a string "0x1234" to a
numerical value.

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list