Update: Oops, oops, oops...I guess I didn't read the question well enough. That's what I get for trying a reply after this kind of week. Reply withdrawn.
No, it doesn't. hex interprets its argument as
being a hex number. But what was asked was to get a hex
representation of a number.
BTW, your $dec_num is misleading. hex just
returns a number. It doesn't make much sense calling that
a decimal number. "decimal" is relevant when we talk about
representing numbers - for instance when reading in
a number, or printing it. But all we do here is storing it.
Most likely in a binary format - but which format it is, is
irrelevant on the level of the language.