Connecting Tech Pros Worldwide Help | Site Map

Negative scalar variable comparision

Newbie
 
Join Date: Oct 2008
Posts: 19
#1: Nov 1 '08
Hello Friends,
Expand|Select|Wrap|Line Numbers
  1.             If 
  2.         $tmp = -524219359 ;
  3.        $tmp1= -532676607;
  4.  
  5.                 if($tmp >0 && $tmp1>0){
  6.                      print(Temporary values are greater than Zero);
  7.                 else {
  8.                     print(Temporary values are less than zero);
  9.                 }
  10.  
May i know what is the result we can get & with some explanation?


Thanks
Raghavendra
Newbie
 
Join Date: Oct 2008
Posts: 19
#2: Nov 1 '08

re: Negative scalar variable comparision


Hello friends,
I got doubt in doing signed hexadecimal comparision.
Here $tmp & tmp1 are negative decimal values , when i convert that numbers as hexadecimal & comparing with the mentioned below i am getting wrong result.
May i the ultimate solution for signed comparision in perl
Expand|Select|Wrap|Line Numbers
  1.  $tmp  = 0xc0211082;
  2.  $tmp1 = 0xc0000082;
  3.  
  4. if($tmp >0 && $tmp1>0){
  5. print("Temporary values are greater than Zero");
  6. }else {
  7. print("Temporary values are less than zero");
  8. }
  9.  
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Nov 1 '08

re: Negative scalar variable comparision


Quote:

Originally Posted by raghavendrap

Hello Friends,

Expand|Select|Wrap|Line Numbers
  1.             If 
  2.         $tmp = -524219359 ;
  3.        $tmp1= -532676607;
  4.  
  5.                 if($tmp >0 && $tmp1>0){
  6.                      print(Temporary values are greater than Zero);
  7.                 else {
  8.                     print(Temporary values are less than zero);
  9.                 }
  10.  
May i know what is the result we can get & with some explanation?


Thanks
Raghavendra

Correct all syntax errors and retry your code. Its pretty much worthless to ask a question then post bad code, we have no way of knowing if you are getting an error from the bad code or if you are using good code and getting an unusual return value, or what? So please try and always post code that has no syntax errors.
Newbie
 
Join Date: Oct 2008
Posts: 19
#4: Nov 3 '08

re: Negative scalar variable comparision


Hello KevinADC,
I am new to perl , i am learning now, please let me know where i did wrong in my code which i have posted? & it would be helpful for me if u guide me by giving answers to my questions,i am very thankfull for you & its very proud for me by learing perl under your guidance.

Thanks
Raghavendra
Reply