| 1 | package EMC::WideSky::Util; | ||
| 2 | |||
| 3 | our @ISA = qw(Exporter); | ||
| 4 | our @EXPORT = qw(dec2hex hex2dec); # Symbols to be exported by default | ||
| 5 | our @EXPORT_OK = qw(); # Symbols to be exported on request | ||
| 6 | our $VERSION = 0.1; | ||
| 7 | |||
| 8 | sub dec2hex { | ||
| 9 | my $dec=shift @_; | ||
| 10 | |||
| 11 | my $out=join("",reverse unpack(H2H2, chr($dec % 256).chr(int($dec/256)) )); | ||
| 12 | $out=~ tr[a-z][A-Z]; | ||
| 13 | return $out; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub hex2dec { | ||
| 17 | my $hex=shift @_; | ||
| 18 | |||
| 19 | my @dec=unpack(C4C4, pack(H2H2,substr($hex,0,2),substr($hex,2,2))); | ||
| 20 | return($dec[0]*256+$dec[1]); | ||
| 21 | } | ||
| 22 |