A
Angus
int xx = 5;
double nextx = ~(--xx);
I was expecting -4 - but get -5. How do I change to yield -4?
double nextx = ~(--xx);
I was expecting -4 - but get -5. How do I change to yield -4?
Angus said:int xx = 5;
double nextx = ~(--xx);
Could you go into a little more detail about why you were expectingI was expecting -4 - but get -5. How do I change to yield -4?
Could you go into a little more detail about why you were expecting
the answer -4? Then I could more easily suggest the kind of change you
really want.
No. ~ flips the bits of the number, so 000......0100 (which is 4 in binary)I expected the -- decrement to make 4 and the ~ operator would then
make 4 negative.
No. ~ flips the bits of the number, so 000......0100 (which is 4 in binary)
becomes 111...1011, which is how -5 is represented. Why not just use
- instead of ~ ?
Angus said:I expected the -- decrement to make 4 and the ~ operator would then
make 4 negative.
Angus said:I wanted to try to transform x to -x(+1) in one operation.
eg take a positive number and make it negative and add 1
int xx = 5;
double nextx = ~(--xx);
I was expecting -4 - but get -5. How do I change to yield -4?
On 17 June, 14:24, (e-mail address removed) (Tim Love) wrote:
I wanted to try to transform x to -x(+1) in one operation.
eg take a positive number and make it negative and add 1
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.