Path: utzoo!mnetor!uunet!husc6!hao!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpcea!hpfcdc!boemker From: boemker@hpfcdc.HP.COM (Tim Boemker) Newsgroups: comp.lang.c Subject: Re: Simple question about: ~ Message-ID: <5080019@hpfcdc.HP.COM> Date: 26 Jan 88 19:07:25 GMT References: <1620006@hpcilzb.HP.COM> Organization: HP Ft. Collins, Co. Lines: 20 > Could someone please explain why the following statements both give the > same answer? x= -y -1; vs. x = ~y; On most computers, integers are stored in two's complement form. For a positive integer, that's the normal representation. For a negative integer, the two's complement is the one's complement plus one. (Adding one may seem curious, but it has an important advantage: there's only one representation for zero. In a one'c complement scheme, both a word of 1's and a word of 0's represent zero.) Let y be a positive integer. -y = ~y + 1 by definition of two's complement -y - 1 = ~y QED.