The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why
the one less at positive Range ? (compared to the negative side..!)
I came to know that it uses 2's compliment internally for storing the
negative numbers . why it uses 2's compliment but not the ones compliment
for storing the negative numbers ? 19 2415
Harshan wrote: The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why the one less at positive Range ? (compared to the negative side..!)
because we need to represent the number 'zero' as well.
I came to know that it
What is 'it' ? Are you referring to the implementation.
uses 2's compliment internally for storing the negative numbers . why it uses 2's compliment but not the ones compliment for storing the negative numbers ?
This is entirely dependent on the machine / implementation.
And ansi C does not have any say on this.
--
Karthik.
harshan,
it is less by one bcos it takes zero into account when
positive numbers are taken care of. i.e. if u want to have
10 smallest non negative numbers it'll b frm 0 -9 not 1-10.
thats why at the positive range its one less than as expected
On Mon, 24 Jan 2005 15:38:29 +0530, Harshan wrote: The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why the one less at positive Range ? (compared to the negative side..!) I came to know that it uses 2's compliment internally for storing the negative numbers . why it uses 2's compliment but not the ones compliment for storing the negative numbers ?
The C language permits a 1's complement or sign-magnitude representation
of signed integers in addition to 2's complement. Your compiler uses 2's
complement almost certainly because that is what the processor it is
targetting uses. Modern processors tend to use 2's complement because it
has some nice properties and can simplify the hardware design (e.g. you
can avoid separate instructions for signed and unsigned addition and
subtraction). An obvious issue with 1's complement and sign-magnitude is
2 separate representations for the number zero.
Lawrence
yes
i think this is coorect because of 2 zeros in 1's compliment . they are
taking 2's compliment for representation of -ve numbers and that consumes
one number for representing zero , but the negative side it is not consuming
the number so it will be 8000 to ffff -ve side and 1 to 7fff +ve
side in hex representation .
but i found that if you exceed the range value the compiler will take wrap
the value , it is somthing circular style.
"Lawrence Kirby" <lk****@netacti ve.co.uk> wrote in message
news:pa******** *************** *****@netactive .co.uk... On Mon, 24 Jan 2005 15:38:29 +0530, Harshan wrote:
The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767)
Why the one less at positive Range ? (compared to the negative side..!) I came to know that it uses 2's compliment internally for storing the negative numbers . why it uses 2's compliment but not the ones
compliment for storing the negative numbers ?
The C language permits a 1's complement or sign-magnitude representation of signed integers in addition to 2's complement. Your compiler uses 2's complement almost certainly because that is what the processor it is targetting uses. Modern processors tend to use 2's complement because it has some nice properties and can simplify the hardware design (e.g. you can avoid separate instructions for signed and unsigned addition and subtraction). An obvious issue with 1's complement and sign-magnitude is 2 separate representations for the number zero.
Lawrence
"Harshan" <ha***********@ in.bosch.com> wrote in message
news:ct******** **@ns2.fe.inter net.bosch.com.. . but i found that if you exceed the range value the compiler will take
wrap the value , it is somthing circular style.
\The\ compiler does not exist. \Your\ compiler (whatever it is) does.
Probably any HW with 2's complement will result in simular behavior, but in
fact, overflowing a signed integer results in undefined behavior, so do not
count on this behavior. I may be *very* different for another
processor/compiler.
PS. Does anyone know any *modern* processors with anything but 2's
complement encoding of signed integers? I can't remember ever running into
one.
In article <41************ ***********@dre ader4.news.xs4a ll.nl>, "dandelion" <da*******@mead ow.net> writes: PS. Does anyone know any *modern* processors with anything but 2's complement encoding of signed integers? I can't remember ever running into one.
I think some processors still support packed decimal in hardware, but
that's in addition to 2's-complement. Which is good, since p-d isn't
a pure binary representation, so a C implementation on a p-d-only
machine would have to emulate all the integer operations.
--
Michael Wojcik mi************@ microfocus.com
Proverbs for Paranoids, 1: You may never get to touch the Master,
but you can tickle his creatures. -- Thomas Pynchon
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Wojcik wrote: In article <41************ ***********@dre ader4.news.xs4a ll.nl>, "dandelion" <da*******@mead ow.net> writes:
PS. Does anyone know any *modern* processors with anything but 2's complement encoding of signed integers? I can't remember ever running into one.
I think some processors still support packed decimal in hardware,
Yes, the zSeries mainframe (of the System 360/370/390 line) still supports
packed decimal in hardware. Most mainframe languages support these native bcd
datatypes directly in the language.
but that's in addition to 2's-complement.
IIRC, BCD support on IBM mainframes originally was an option; you could order
the original 'basic' system with binary integer support only, a 'scientific'
system with binary integer and floatingpoint support or a 'business' system with
binary integer and BCD support. The "System 360" changed that by incorporating
both the 'business' and 'scientific' support into one hardware architecture.
Legend has it that the system was named "360" because it was an 'all
encompasing' processor, and the name alluded to the 360 degrees of a complete
circle representing the complete circle of basic, business and scientific computing.
Which is good, since p-d isn't a pure binary representation, so a C implementation on a p-d-only machine would have to emulate all the integer operations.
- --
Lew Pitcher
IT Consultant, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFB9TtEagV FX4UWr64RAuUsAK CT/nW+GjHQaRhHffN4 QgzA/K3orQCg8CZU
gC23OnjwVDSsFCQ tA5xUay0=
=LHK+
-----END PGP SIGNATURE-----
"Harshan" <ha***********@ in.bosch.com> wrote in message
news:ct******** **@ns2.fe.inter net.bosch.com.. . The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767)
It might be for your implementation, but the range required by
the C standard is -32767 through 32767 inclusive (but an implementation
is allowed to provide a larger range.
Why the one less at positive Range ? (compared to the negative side..!)
Because apparently your implementation takes advantage of its
specific representation for integers. I came to know that it uses 2's compliment internally for storing the negative numbers . why it uses 2's compliment but not the ones compliment for storing the negative numbers ?
Because that's what its authors decided to do. The language
standard allows one's complement, two's complement, or
signed magnitude.
-Mike
Mike Wahler wrote: "Harshan" <ha***********@ in.bosch.com> wrote in message news:ct******** **@ns2.fe.inter net.bosch.com.. .
The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767)
It might be for your implementation, but the range required by the C standard is -32767 through 32767 inclusive (but an implementation is allowed to provide a larger range. Why the one less at positive Range ? (compared to the negative side..!)
Because apparently your implementation takes advantage of its specific representation for integers.
I came to know that it uses 2's compliment internally for storing the negative numbers . why it uses 2's compliment but not the ones compliment for storing the negative numbers ?
Because that's what its authors decided to do. The language standard allows one's complement, two's complement, or signed magnitude.
-Mike
It's what the authors of the CPU's accumulator decided to do.
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Dutrow |
last post by:
I searched around on the net for a bit, couldn't find anything though.
I would like to find some code for a function where I input A Range Of
Integers
For example: Function( 1, 100 );
And the function will return me an array holding a random subset of integers
in that range of a size that I specify
So the Function would Probabaly look something like this:
|
by: Steve R. Hastings |
last post by:
When you compile the expression
for i in range(1000):
pass
does Python make an iterator for range(), and then generate the values
on the fly? Or does Python actually allocate the list
and then step through it?
I was under the impression that recent releases of Python optimize this
|
by: Chad |
last post by:
What is the difference between range and precision in c? Also, if c
doesn't support fixed point numbers, how is the addition of two
integers possible?
Chad
|
by: pcnerd |
last post by:
I'm trying to create a program that plots randomly colored pixels on a bitmap
& then displays the bitmap. When I run the program, I see the pixels being
plotted down the left side of the form. When it gets to the bottom, the
"Argument out of range exception" occurs. So, obviously the program starts.
The Help tells me that the argument isn't within the range of values, but it
doesn't explain how to fix the problem. So the Help doesn't help!...
|
by: Joe Van Dyk |
last post by:
Hi,
Say I have:
class Latitude
{
friend bool operator==(const Latitude& lhs, const Latitude& rhs);
friend bool operator<(const Latitude& lhs, const Latitude& rhs);
friend std::ostream& operator<<(std::ostream& os, const Latitude& l);
public:
| |
by: Thanigaivel |
last post by:
Hi All,
i have assigned some large positive int value (32 bit length) X to unsigned int variable and due to the range constraints that variable stores the same positive value X in negative representation say Y (where Y<0).
Now my question is If Y = -1018059492 what would be the value of X? And how to do this converision?
Thanks in advance!
|
by: Rahul |
last post by:
Hello Everyone,
I was wondering what is the datatype of obj?
Is it an integer? If so what if the number of enumerations crosses
over the limit of an integer (2^32-1)?
enum
{
CLUB,
DIAMONDS
|
by: deepak |
last post by:
Hi,
Can someone give the standard function which can create positive
integer value in C?
Thanks,
Deepak
|
by: Rafael Cunha de Almeida |
last post by:
Hi,
I've found several sites on google telling me that I shouldn't use
rand() % range+1
and I should, instead, use something like:
lowest+int(range*rand()/(RAND_MAX + 1.0))
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |