473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Nov 1 '08 #1
5 6353
KevinADC
4,059 Expert 2GB
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
Nov 1 '08 #2
Hello,
Can you please be clear about what your are trying to explain me.



Thanks
Raghavendra
Nov 3 '08 #3
KevinADC
4,059 Expert 2GB
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. }
Nov 3 '08 #4
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
Nov 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Tom Goulet | last post by:
Hello, My question basically is: What is the opposite of the following? | "%08X" % -1 I want to convert a string of hexadecimal characters to the signed integer they would have been before...
38
by: Keith | last post by:
I've been reading and looking on the internet - but I just can't fin this. Perhaps I'm approaching this the wrong way - code-wise I'm attempting to learn how "things" work in VBNET by creating...
25
by: junky_fellow | last post by:
Is there any way by which the overflow during addition of two integers may be detected ? eg. suppose we have three unsigned integers, a ,b, c. we are doing a check like if ((a +b) > c) do...
9
by: Chris Botha | last post by:
Hi, I have an UInt32 and want to stick the value into an Integer and get an Overflow exception, BUT using C# the same value can be casted into an int and the value is as expected. The Hex value is...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
40
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at:...
13
by: Freaker85 | last post by:
Hello, I am new at programming in C and I am searching a manner to parse a string into an integer. I know how to do it in Java, but that doesn't work in C ;o) I searched the internet but I...
42
by: thomas.mertes | last post by:
Is it possible to use some C or compiler extension to catch integer overflow? The situation is as follows: I use C as target language for compiled Seed7 programs. For integer computions the C...
6
by: Chris Becke | last post by:
I *know* my CPU has opcodes that can do this - when adding (or subtracting) there is a carry flag that can be invoked to make the result essentially 1 bit longer than the data size used in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.