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.
Asked
Active
Viewed 3,801 times
1 Answers
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