Many Happy Returns

  • Thread starter Richard Heathfield
  • Start date
R

Rocke Robertson

Joona said:
Perhaps I should have explained in more detail. The ~ operator
implements one's complement arithmetic by inverting all the bits. Thus
you get "all-bits-one" for ~0, because "all-bits-zero" is 0.
But! If the number is signed, two's complement arithmetic comes into
play *after* that. On a two's complement machine, any number whose
leftmost bit is 1 is taken as negative, and "all-bits-one" is -1 on
such a machine. Therefore, on a two's complement machine, ~0 == -1.

Boy, I'm sure glad someone understands this stuff cause this last post by Joona just completely lost
me....
 
C

Christopher Benson-Manica

Joona I Palaste said:
Perhaps I should have explained in more detail. The ~ operator
implements one's complement arithmetic by inverting all the bits. Thus
you get "all-bits-one" for ~0, because "all-bits-zero" is 0.

Is 0 indeed equivalent to 0x00000000? (I ask because I don't know...)
 
H

Hallvard B Furuseth

Christopher said:
Is 0 indeed equivalent to 0x00000000? (I ask because I don't know...)

Yes. Both mean 0.

BTW, in case you were thinking that 0x00000000 is a special way to say
'all bits zero': Not so. (void*)0x00000000 means the same as (void*)0,
whose representation need not be all bits zero. The _integer_ 0 does
have all bits zero, though. Possibly except padding bits.
 
M

Mark Gordon

Is 0 indeed equivalent to 0x00000000? (I ask because I don't know...)

How could it not? The base of numbers in the source code does not affect
the value so 0==0x000000000000000000000000000000 and 15==0xf etc.

Or are you asking if the representation of 0 is specified by the
standard as being all bits zero?
 

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

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top