What does this mean???

S

Shraddha

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 "...
 
J

Joe Wright

Shraddha said:
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.
 
O

osmium

Shraddha said:
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 "...

Tilde is the one's complement operator. I would not think of that as
bulletproof code, the results might well be different on a one's complement
machine than they are on a two's complement machine. The result is
"negative zero" on a one's complement machine.
 
R

Richard Heathfield

osmium said:

Tilde is the one's complement operator.

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

osmium

Richard Heathfield said:
osmium said:



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

I don't know if that is some of that famous British humour or what. It is
the one's complement operator, it does *not* form a proper two's complement.
 
R

Richard Heathfield

osmium said:
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.
 
O

osmium

Richard Heathfield said:
osmium said:


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).


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.
 
R

Richard Heathfield

osmium said:
Some of your alleged humour is on a par with your food.

I say again, there is no humour intended here. I am being perfectly
serious. I don't know what amusement *you* see in this discussion, but
I'm not seeing any at all.
If I had not
responded an innocent passerby who didn't try to parse your response,
as I did, could be misled badly.

I don't see how. You said "Tilde is the one's complement operator" and I
replied "No, it's the ones' complement operator". The correction seems
plain enough to me.

If you think my correction is spurious, I invite you to check the Knuth
reference I gave.
 
O

osmium

Richard Heathfield said:
osmium said:


I say again, there is no humour intended here. I am being perfectly
serious. I don't know what amusement *you* see in this discussion, but
I'm not seeing any at all.


I don't see how. You said "Tilde is the one's complement operator" and I
replied "No, it's the ones' complement operator". The correction seems
plain enough to me.

If you think my correction is spurious, I invite you to check the Knuth
reference I gave.

It has nothing to do with the legitimacy of what you are saying. You know,
this English language is expressive enough to actually say what you mean
instead of hiding the meaning behind a veil. I see no point whatsoever in
being so subtle on such a thing, as I said, your initial post could easily
mislead someone.

FWIW, K&R spell it my way. My work is done here.
 
C

Charles Bailey

Tilde is the one's complement operator. I would not think of that as
bulletproof code, the results might well be different on a one's complement
machine than they are on a two's complement machine. The result is
"negative zero" on a one's complement machine.

Given the presence of the shift operator, I would have thought that it
is more important to the author that i has the all ones bit pattern
that it represents any particular number. For this reason ~0 is
initially a more logical choice than -1.

We don't know what i is, but whether the loop will terminates if it is
signed is implementation defined. If the implementation uses a two's
complement representation and the shift operator for signed ints on
the implementation does an arithmetic right shift (shifts in the sign
bit and leaves the sign bit unchanged) then the loop will not
terminate.

For this reason, if this is to be portable code, i should be unsigned.
If i is unsigned then -1 and ~0 are both equivalent as both are
guaranteed to represent 2^N - 1.

OK, the last paragraph isn't true :). Technically -1 and ~0U are
guaranteed to represent 2^N - 1 where N is the number of value bits
in the representation of unsigned int.

OK, the last paragraph isn't true :). If i is wider than an int
(supposed it is an unsigned long) then ~0UL is required. In general,
the constant 0 needs to be widened to the correct width before the ~
operator is applied.
 
R

Richard Heathfield

osmium said:
It has nothing to do with the legitimacy of what you are saying. You
know, this English language is expressive enough to actually say what
you mean instead of hiding the meaning behind a veil. I see no point
whatsoever in being so subtle on such a thing

Nor do I. Had I intended to be subtle, I would have *been* subtle.
as I said, your initial post could easily mislead someone.

Only someone easily misled. Whilst I agree that there is no shortage of
such people, they probably wouldn't make very good C programmers
anyway.
FWIW, K&R spell it my way.

Fine, so submit a bug report.
My work is done here.

Er, okay, if you say so.
 
M

Mark McIntyre

Some of your alleged humour is on a par with your food.

I'm curious as to how often you've eaten at the Heathfield
household....
If I had not
responded an innocent passerby who didn't try to parse your response, as I
did, could be misled badly.

I doubt it.
--
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
 
M

Mark McIntyre

FWIW, K&R spell it my way.

So ? That merely tells you the quality of proofreading. You would not
believe some of the dreck that my missus has had to send back to
alleged proofreaders.

--
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
 
R

Richard Tobin

Tilde is the one's complement operator.
[/QUOTE]
Actually, it's the ones' complement operator, because it complements
many ones.

Presumably you mean "with respect to many ones". At least, that's
what Knuth says, and I believe it's from him that this view derives.
"Two's complement", however, is correct.

.... because, so it is claimed, it complements with respect to a single
power of two.

But I find this argument unconvincing. The apostrophe suggests that
they are complements *of* one and two, which they aren't. It would be
reasonably natural to refer to the one- or two-complement of a single
bit, and extended the terms unchanged to cover the multi-bit case.

But in any case the term "twos complement", regardless of apostrophe,
does not capture the key point of that representation. It is the
truncated form of the result of applying the usual binary arithmetic
to a conceptually infinite strings of bits. If you blindly subtract 1
from 0 in binary, you get ones all the way.

-- Richard
 
R

Richard Heathfield

Richard Tobin said:
Actually, it's the ones' complement operator, because it complements
many ones.

Presumably you mean "with respect to many ones".[/QUOTE]

Call me Mr I Didn't Get Any Sleep Last Night. You're right - that's what
I meant.
At least, that's
what Knuth says, and I believe it's from him that this view derives.

Quite so.
... because, so it is claimed, it complements with respect to a single
power of two.

But I find this argument unconvincing.

Well, then, I can only suggest that you attempt to claim your $2.56 from
DEK. :)
 
D

Dave Vandervies

I'm curious as to how often you've eaten at the Heathfield
household....

If the food is as good as the humour, I should definitely make plans to
do so in the (unlikely) event I'm ever on that side of the world.


dave

--
Dave Vandervies (e-mail address removed)
I can certainly imagine C370 programmers living in their own world.
It's very dark in there, too; no windows...
--Lawrence Kirby and Richard Heathfield in comp.lang.c
 
K

Keith Thompson

If the food is as good as the humour, I should definitely make plans to
do so in the (unlikely) event I'm ever on that side of the world.

If his food is like his humor, I fear it may be too dry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top