473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does this mean???

I got a small programm on net...but there was different initialisation
that I saw...

It was as follows:

for ( i = ~0 ; i ; i>>=1);

right shift is ok..But what is meaned by " i = ~0 "...

Jun 19 '07
26 1999
osmium wrote:
"Richard Heathfield" writes:
> osmium said:
>>"Richard Heathfield" writes:
osmium said:

<snip>

Tilde is the one's complement operator.

Actually, it's the ones' complement operator, because it
complement s many ones. "Two's complement", however, is correct.

I don't know if that is some of that famous British humour or
what.

Nope.
>>It is the one's complement operator,

No, it's the ones' complement operator. Observe the position of
the apostrophe. If you disagree, take it up with Knuth (TAOCP
Vol 2, Section 4.1).
>>it does *not* form a proper two's complement.

I didn't say it did. I was referring to your correct positioning
of the apostrophe in "two's complement", later in your article.

Some of your alleged humour is on a par with your food. If I had
not responded an innocent passerby who didn't try to parse your
response, as I did, could be misled badly.
What humor? I think he is perfectly serious. Grammar counts.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com

Jun 19 '07 #21
Joe Wright wrote:
Barry Schwarz wrote:
><jo********@co mcast.netwrote:
>>Shraddha wrote:
.... snip ...
>>>>
right shift is ok..But what is meaned by " i = ~0 "...

Same as "i = -1;" I suppose.

Not on a 1's complement or a signed magnitude machine.

Of course but these machines imaginary aren't they?
To the same extent that -1 is.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 19 '07 #22
CBFalconer wrote:
Joe Wright wrote:
>Barry Schwarz wrote:
>><jo********@c omcast.netwrote :
Shraddha wrote:
... snip ...
>>>>right shift is ok..But what is meaned by " i = ~0 "...
>
Same as "i = -1;" I suppose.
Not on a 1's complement or a signed magnitude machine.
Of course but these machines imaginary aren't they?

To the same extent that -1 is.
This is a very tough room. Let me try again. The question..
"what is meaned by " i = ~0 "..." might translate to..

int i = ~0;

...What goes on here?

The 0 of course in an integer value with all bits 0. The prefix tilde
performs a binary complement of the value, in this case to all bits 1.

The value of 'all bits 1' depends on how you look at it.

Two's complement suggests -1.
One's complement suggests -0.
Signed Magnitude maybe minus INT_MAX?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jun 19 '07 #23
On Tue, 19 Jun 2007 13:29:20 -0400, in comp.lang.c , Joe Wright
<jo********@com cast.netwrote:
>Barry Schwarz wrote:
>Not on a 1's complement or a signed magnitude machine.
Of course but these machines imaginary aren't they?
Well, certainly some of them are now extraterrestria l

http://en.wikipedia.org/wiki/Apollo_Guidance_Computer

while others appeared out of the blue, as it were...

http://en.wikipedia.org/wiki/IBM_7090
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 19 '07 #24
Joe Wright wrote:
CBFalconer wrote:
>Joe Wright wrote:
>>Barry Schwarz wrote:
<jo********@ comcast.netwrot e:
Shraddha wrote:
... snip ...
>>>>>right shift is ok..But what is meaned by " i = ~0 "...
>>
Same as "i = -1;" I suppose.
Not on a 1's complement or a signed magnitude machine.
Of course but these machines imaginary aren't they?

To the same extent that -1 is.
This is a very tough room. Let me try again. The question..
"what is meaned by " i = ~0 "..." might translate to..

int i = ~0;
Who says i is declared as int? The original poster didn't, as far as I've
seen. If i is not declared as int, it is important to remember than ~0 is
evaluated as type int (the type of 0), and the result is converted to the
type of i. That is,

unsigned i = ~0;

is not equivalent to

unsigned i = 0;
i = ~i;

even though in this case, for two's complement, the result will be the same.
..What goes on here?

The 0 of course in an integer value with all bits 0. The prefix tilde
performs a binary complement of the value, in this case to all bits 1.

The value of 'all bits 1' depends on how you look at it.

Two's complement suggests -1.
Yes.
One's complement suggests -0.
As was mentioned elsethread, it's called "ones' complement".

-0 is never negative zero. If negative zero is supported, it will compare
equal to plain zero, but you don't get negative zero as a result of any
non-bitwise arithmetic operation, including negation. -0 is equivalent to
+0 .

And ones' complement systems are allowed to say the behaviour is undefined
if ~0 is evaluated. Negative zero need not be supported, and if it is not,
then all bits set is a trap representation.
Signed Magnitude maybe minus INT_MAX?
It's called "sign and magnitude", but right. Which of course equals INT_MIN
for these systems.
Jun 19 '07 #25
Joe Wright wrote:
Barry Schwarz wrote:
>On Mon, 18 Jun 2007 20:28:36 -0400, Joe Wright
<jo********@co mcast.netwrote:
>>Shraddha wrote:
I got a small programm on net...but there was different initialisation
that I saw...

It was as follows:

for ( i = ~0 ; i ; i>>=1);

right shift is ok..But what is meaned by " i = ~0 "...

Same as "i = -1;" I suppose.

Not on a 1's complement or a signed magnitude machine.
Of course but these machines imaginary aren't they?
Of course they are. Completely imaginary. And THAT'S
why the committees who wrote and revised the Standards made
allowance for them. Even when they tightened the allowable
representations in C99, they still allowed ones' complement
and signed magnitude. Simply decreeing two's complement
would have made a lot of things simpler, but the committees
were made up entirely of masochists who loved to make trouble
for themselves. That's why you needn't worry your pretty
little head about it: All the world is a two's complement
32-bit Little-Endian IEEE-floating-point dosbox, and don't
let anyone tell you any different.

Or to put it another way: A friend of mine likes to say
that computing is a fashion-driven industry. Fashions come,
and fashions go, and fashions come again. You can write your
program for this season's hem lines and color schemes, or you
can attempt something a little less transitory. There are,
after all, some distinct infelicities in two's complement:
the fact that abs(n) cannot be implemented reliably stands
out as an ugliness that neither of the alternatives suffer
from, and tomorrow's system couturier may reject that ugliness.
Trap representations for integers are Out today, but in the
face of viral onslaught might not tomorrow's machine revive
the old practice of explicitly-typed data?

Sometimes it doesn't make sense to sacrifice all other goals
on the altar of portability: Portability is just one among many
desirable attributes of a program. But there are *very* few
reasons to engage in gratuitous importabilities like those(?)
in the above code example. You may not particularly like the
ruffles-with-polka-dots theme that all the designers will put
on the runways next year, but it costs you little or nothing
to accommodate it -- and if you don't, none of the hot models
will wear your code.

--
Eric Sosman
es*****@acm-dot-org.invalid
Jun 20 '07 #26
Eric Sosman <es*****@acm-dot-org.invalidwrot e:
Or to put it another way: A friend of mine likes to say
that computing is a fashion-driven industry. Fashions come,
and fashions go, and fashions come again. You can write your
program for this season's hem lines and color schemes, or you
can attempt something a little less transitory. There are,
after all, some distinct infelicities in two's complement:
the fact that abs(n) cannot be implemented reliably stands
out as an ugliness that neither of the alternatives suffer
from, and tomorrow's system couturier may reject that ugliness.
Trap representations for integers are Out today, but in the
face of viral onslaught might not tomorrow's machine revive
the old practice of explicitly-typed data?
Mind you, for the fashion industry it seems to be lucrative to work only
to today's fashion, and let the airheaded customers buy each year's
fashion in turn. It doesn't seem to do Microsoft any harm, either.

Whether that is a business model you wish to strive for is on each
programmer's own conscience. But lucrative it is.

Richard
Jun 20 '07 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
14865
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
3
29684
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification says: "The 'visibility' property takes the value 'collapse' for row, row group, column, and column group elements. This value causes the entire row or column to be removed from the display, and the space normally taken up by the row or column to...
86
7807
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that: http://www.clagnut.com/blog/348/ I hope that's going to be a good discussion! Michael
44
4289
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there must be many know the answer here. thanks
2
10219
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table . GO
121
10188
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
51
4569
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
1
8746
by: Frank Rizzo | last post by:
Some of the classes in the framework are marked as thread-safe in the documentation. In particular the docs say the following: "Any public static (*Shared* in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe." What exactly does this mean? Does this mean that if I call a shared method from 2 different threads, nothing whacky will happen? Also when it says that instance members...
13
5061
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
550
by: JoeC | last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; What does this mean? I have seen v=&var->member.thing; but what does it mean when you change the & for int?
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3
2941
bsmnconsultancy
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...

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.