Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-lcc!rutgers!clyde!cbatt!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!h.cc.purdue.edu!pur-phy!mrstve!rjk From: rjk@mrstve.UUCP (Richard Kuhns) Newsgroups: comp.lang.c Subject: Re: bit patterns of all ones Message-ID: <595@mrstve.UUCP> Date: Fri, 26-Dec-86 10:14:07 EST Article-I.D.: mrstve.595 Posted: Fri Dec 26 10:14:07 1986 Date-Received: Sat, 27-Dec-86 00:37:17 EST References: <1382@hoptoad.uucp> <690001@hplsla.HP.COM> <1527@hoptoad.uucp> Reply-To: rjk@mrstve.UUCP (Richard Kuhns) Organization: Mr sTVe's, Lafayette IN Lines: 18 In article <1527@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes: >Ken Ballou seems to have presented good and valid reasons derived from H&S >that (unsigned)-1 must have all the bits on. So far nobody has refuted >him. I think he's right -- the cast to unsigned *must*, by the C language >definition, convert whatever bit pattern -1 has into all ones. This >is no worse than casting -1 to float causing a change its bit pattern -- >and it's for the same reason. I don't understand. On a ones-complement machine, -1 is represented by sizeof(whatever) - 1 ones followed by a zero. How does casting this value to unsigned get rid of the zero? To wit: 00000001(binary) = 1 (decimal) 11111110(binary) = -1 (decimal, ones complement, signed) If the second value above is cast to unsigned, we end up with 254(decimal). What does this have to do with a bit pattern of all ones? -- Rich Kuhns {ihnp4, decvax, etc...}!pur-ee!pur-phy!mrstve!rjk