How to manipulate integer overflow in hexadecimal.(Urgent)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghavendrap
    New Member
    • Oct 2008
    • 19

    #1

    How to manipulate integer overflow in hexadecimal.(Urgent)

    Code:
    $tmp  = 0xc0211082;
     $tmp1 = 0xc0000082;
    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?
    Code:
     $tmp  = 0xc0211082;
     $tmp1 = 0xc0000082;
    
     $tmp2_dec = hex($tmp);
     $tmp3_dec = hex($tmp1);
    
     printf("Decimal Value tmp is %d \n",$tmp);
     printf("Decimal Value tmp1 is %d \n",$tmp1);
     printf("Decimal Value tmp2 is %d \n",$tmp2_dec);
     printf("Decimal Value tmp3 is %d \n",$tmp3_dec);
    
    if($tmp2_dec >0 && $tmp3_dec >0){
    print("Temporary values are greater than Zero \n");
    }else {
    print("Temporary values are less than zero \n");
    }
    Thanks
    Raghavendra
    Last edited by numberwhun; Nov 1 '08, 01:37 PM. Reason: Please use code tags!
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    As the hex() functions manpage explains:

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

    Comment

    • raghavendrap
      New Member
      • Oct 2008
      • 19

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



      Thanks
      Raghavendra

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        please read the links next time:

        Code:
        $tmp2_dec = oct('0xc0211082');
        $tmp3_dec = oct('0xc0000082');
        
        print "$tmp2_dec   $tmp3_dec\n";
        
        $t2 = sprintf "%d", $tmp2_dec;
        $t3 = sprintf "%d", $tmp3_dec;
        
        print "$t2 $t3\n";
         
        printf ("Decimal Value tmp is %d \n",$tmp2_dec);
        printf("Decimal Value tmp1 is %d \n",$tmp3_dec);
        
        if($t2 > 0 && $t3 > 0){
           print("Temporary values $t2 and $t3 are greater than Zero \n");
        }else {
           print("Temporary values $t2 and $t3 are less than zero \n");
        }

        Comment

        • raghavendrap
          New Member
          • Oct 2008
          • 19

          #5
          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

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6

            Comment

            Working...