4

Hi folks i am new to Perl. I have a hex Chanel data(24 bits) 'fe284b' and '018263' i want it's equivalent signed integers '-120757' and '98915' respectively. Please help me how to do this in Perl.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
ImDrPatil
  • 197
  • 1
  • 5
  • 11

1 Answers1

4

Use the hex()function to convert a hex string to its numeric equivalent. Then if the value should have been negative, make it so.

$hex = 'fe284b';
$value = hex($hex);
$value -= 0x1000000 if $value >= 0x800000;
print $value;

Output:

-120757
Adrian Pronk
  • 13,486
  • 7
  • 36
  • 60