http://www.perlmonks.org?node_id=1181532


in reply to Multiply Hex values

There is a wrong understanding in your post.

Numbers exist independently of their (hexadecimal, decimal or other) representations.

From Perldoc: hex interprets EXPR as a hex string and returns the corresponding value.

The hex function converts a string into a number, it does not convert an hex number into a decimal number (even though if you print the output of hex, it will be printed as a decimal number, this does not imply that they're stored as decimal numbers, as this is irrelevant, they are stored as numbers).

Now, if you want to multiply numbers, they have some how to be numbers. So you need to convert your strings into numbers (not decimal or hexadecimal numbers), or at least something that Perl understands as numbers. So converting your hexadecimal strings to numbers is the right way to do it. And, once you've done that, you can multiply your numbers, and then print out the resulting number value in any representation you wish, including hexadecimal representation or any other one.