Path: utzoo!attcan!uunet!snorkelwacker!spdcc!ima!haddock!karl@haddock.ima.isc.com From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: all bits zero? Message-ID: <16245@haddock.ima.isc.com> Date: 21 Mar 90 18:49:17 GMT References: <2108@gmdzi.UUCP> Sender: karl@haddock.ima.isc.com Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 18 Supersedes: <16237@haddock.ima.isc.com> In article <2108@gmdzi.UUCP> wittig@gmdzi.UUCP (Georg Wittig) writes: >Does ANSI C require that in the internal representation of the integer >constant ``0'' all bits are zero? Assuming it's not in a pointer context--in which case it would have been a null pointer constant, not an integer constant, despite having the same spelling--yes. Non-negative integers, signed or unsigned, whether formed by constants of any radix or by run-time expressions, are required to be represented in a "pure binary system". Without such a guarantee, the bitwise operators would be much less useful. Much less is said about negative integers. The value -1 looks like 1111 in two's complement, 1110 in one's complement, and 1001 in sign-magnitude. All of these (and presumably even stranger things) are legal; in the latter two cases a conversion from signed int to unsigned int actually entails a change in the bit-pattern (since (unsigned)-1 == UINT_MAX which looks like 1111). Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint