Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

from hex to signed int

Status
Not open for further replies.

theSnail

Technical User
Jul 2, 2007
4
IT
it's not christmas time but i'm lost inside pack-ing and unpack-ing!

can someone unpack me and show the way to get a signed integer from a one byte long hex?

thanks
theSnail
 
Code:
my $int = oct("0x[COLOR=red]9C[/color]");

where 9C is your one byte hex code (00..FF)

-------------
[url=http://www.cuvou.com/]Cuvou.com[/url] | My personal homepage
[url=http://www.project-fearless.com]Project Fearless[/url] | My web blog
 
uhm ! :)
but

what's the oct value that corresponds to "-23" , just for example.
 
afaik, hexadecimal doesn't support negative numbers... not in one byte, anyway, because one byte can only range from 00 to FF... or, 0 to 255, with no room for negative numbers.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Yes, as Kirsle says, simply define your range and translate it yourself.

Code:
my @n = (-127.. 128);

my @correctRange = map {$_ + 127} @n;

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top