Connecting Tech Pros Worldwide Help | Site Map

How to manipulate integer overflow in hexadecimal.(Urgent)

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 1st, 2008, 07:12 AM
Newbie
 
Join Date: Oct 2008
Posts: 19
Default How to manipulate integer overflow in hexadecimal.(Urgent)

Expand|Select|Wrap|Line Numbers
  1. $tmp  = 0xc0211082;
  2.  $tmp1 = 0xc0000082;
  3.  
Hello friends,
I got doubt when i am converting negative hexadecimal to a decimal number.Please look at mentioned example below.
In the below example my question is when i am converting an hexadecimal to an decimal number i am getting integer overflow in hexadecimal? But the actual values of $tmp & $tmp1 in decimal is signed numbers i.e -1071574910,-1073741694 respectively.
How to manipulate this type of situations?
Expand|Select|Wrap|Line Numbers
  1.  $tmp  = 0xc0211082;
  2.  $tmp1 = 0xc0000082;
  3.  
  4.  $tmp2_dec = hex($tmp);
  5.  $tmp3_dec = hex($tmp1);
  6.  
  7.  printf("Decimal Value tmp is %d \n",$tmp);
  8.  printf("Decimal Value tmp1 is %d \n",$tmp1);
  9.  printf("Decimal Value tmp2 is %d \n",$tmp2_dec);
  10.  printf("Decimal Value tmp3 is %d \n",$tmp3_dec);
  11.  
  12. if($tmp2_dec >0 && $tmp3_dec >0){
  13. print("Temporary values are greater than Zero \n");
  14. }else {
  15. print("Temporary values are less than zero \n");
  16. }
  17.  
Thanks
Raghavendra

Last edited by numberwhun; November 1st, 2008 at 01:37 PM. Reason: Please use code tags!
Reply
  #2  
Old November 1st, 2008, 06:23 PM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,027
Default

As the hex() functions manpage explains:

To convert strings that might start with either 0, 0x, or 0b, see oct .

http://perldoc.perl.org/functions/oct.html
Reply
  #3  
Old November 3rd, 2008, 05:12 AM
Newbie
 
Join Date: Oct 2008
Posts: 19
Default

Hello,
Can you please be clear about what your are trying to explain me.



Thanks
Raghavendra
Reply
  #4  
Old November 3rd, 2008, 06:30 PM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,027
Default

please read the links next time:

Expand|Select|Wrap|Line Numbers
  1. $tmp2_dec = oct('0xc0211082');
  2. $tmp3_dec = oct('0xc0000082');
  3.  
  4. print "$tmp2_dec   $tmp3_dec\n";
  5.  
  6. $t2 = sprintf "%d", $tmp2_dec;
  7. $t3 = sprintf "%d", $tmp3_dec;
  8.  
  9. print "$t2 $t3\n";
  10.  
  11. printf ("Decimal Value tmp is %d \n",$tmp2_dec);
  12. printf("Decimal Value tmp1 is %d \n",$tmp3_dec);
  13.  
  14. if($t2 > 0 && $t3 > 0){
  15.    print("Temporary values $t2 and $t3 are greater than Zero \n");
  16. }else {
  17.    print("Temporary values $t2 and $t3 are less than zero \n");
  18. }
Reply
  #5  
Old November 4th, 2008, 04:59 AM
Newbie
 
Join Date: Oct 2008
Posts: 19
Default

Thank you very much kevin
Can u please provide me some useful links of perl, i need to write automation script for assembly instructions & need to generate .asm file..

Thanks
Raghvendra
Reply
  #6  
Old November 4th, 2008, 06:03 AM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,027
Default

http://bytes.com/forum/thread790489.html
http://www.perlmonks.com/index.pl?node=Tutorials
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.