CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Help with 2byte representation

 



hem
User

Oct 21, 2012, 11:58 AM

Post #1 of 2 (1134 views)
Help with 2byte representation Can't Post

Hi

I have a hex value as input = FF28. Its a 2 byte integer.
If i convert it to decimal using a calculator the decimal value -216

How can i do that conversion in Perl . I have tried using a few combinations with unpack but none of them gives me -216

Thanks in advance


hem
User

Oct 21, 2012, 2:41 PM

Post #2 of 2 (1131 views)
Re: [hem] Help with 2byte representation [In reply to] Can't Post

Got it


Code
use strict; 
my $An = unpack ('s',pack ('S',hex('ff28')));
print "A= $An\n";

C:\Perl64\OnesComplement>perl Ones.pl
A= -216


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives