Consider the following code:
$BB = -2181087916;
$AA = (int)$BB;
$AA = intval($BB);
On some systems, $AA will be int(-2147483648), which is actually
consistent with the documentation.
On most systems, however, $AA will be int(2113879380), which is the
same value truncated at 32 bits.
I actually need the latter behavior, as it needs to duplicate Delphi
code, which, like C, behaves the same way.
This is encryption code that does a bunch of calculations on signed
32-bit numbers and ignores any overflows.
Any ideas how I can do this?
--Bruce 2 1524
Bruce wrote: Consider the following code:
$BB = -2181087916; $AA = (int)$BB; $AA = intval($BB);
On some systems, $AA will be int(-2147483648), which is actually consistent with the documentation.
On most systems, however, $AA will be int(2113879380), which is the same value truncated at 32 bits.
I actually need the latter behavior, as it needs to duplicate Delphi code, which, like C, behaves the same way.
This is encryption code that does a bunch of calculations on signed 32-bit numbers and ignores any overflows.
Any ideas how I can do this?
--Bruce
It's never a good idea to depend on hardware dependent features like the
handling of overflow. They have a tendency to break when you move to a
different hardware platform.
I guess you could do some testing and bit manipulation on it, but that's
adding more complexity to the code (and more chances for it to break).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
On 2006-02-18, Bruce <bv********@gmail.com> wrote: Consider the following code:
$BB = -2181087916; $AA = (int)$BB; $AA = intval($BB);
On some systems, $AA will be int(-2147483648), which is actually consistent with the documentation.
On most systems, however, $AA will be int(2113879380), which is the same value truncated at 32 bits.
I actually need the latter behavior, as it needs to duplicate Delphi code, which, like C, behaves the same way.
This is encryption code that does a bunch of calculations on signed 32-bit numbers and ignores any overflows.
Any ideas how I can do this?
after that do this.
$AA= (( $AA + 2147483648 ) & 4294967295) - 2147483648 ;
it should give the result you want on 64-bit machines
and be harmless on 32-bit machines.
Bye.
Jasen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Christmann |
last post by:
Hi,
just a general question.
Which data type is more precise for large values:
float or double?
Thank you.
Chris
|
by: Sona |
last post by:
I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share a #define macro or
something with me for doing this? Thanks
Sona
|
by: Johnathan Doe |
last post by:
I can google search to find the range of values that can be represented
in a float by reading up on the IEEE std, but is that the same as how
many distinct values that can go in a float type?
...
|
by: Dave win |
last post by:
Hi all:
I'm confused with the expression "(float *())".
Book says that this is a cast. But, I have no idea of this expr.
why could this expr ignore the variable???
Thanx!!!
|
by: Anders Würtz |
last post by:
i have an assignment to iterate through a collection containing
different types of numeric values (float, double, int, byte, short etc.)
and to add 1 to all of them. I tried with array and...
|
by: Erick-> |
last post by:
hi all...
I've readed some lines about the difference between float and double
data types... but, in the real world, which is the best? when should we
use float or double??
thanks
Erick
|
by: psbasha |
last post by:
Hi ,
I have a list as shown below, when access the list at particular location ,say
pointList.The values what I have stored is different to the output.There is a decimal precision change in the...
|
by: JDT |
last post by:
Hi,
It seems that using floats as the first tupelo for an STL map (shown
below) can cause problems but I don't remember what the problems were.
Is it common practice to use a structure like...
|
by: Gabriel Genellina |
last post by:
En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <brennan.ron@gmail.com>
escribi�:
What is a "multipart"? I know MIME multipart messages but they don't seem
to apply here...
From your other...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |