Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Hexadecimal/octal constants Message-ID: <15536@smoke.brl.mil> Date: 21 Mar 91 00:47:08 GMT References: <11206@dog.ee.lbl.gov> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 28 In article <11206@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes: >In article rjohnson@shell.com (Roy Johnson) writes: >>Is it true on every platform that 0xf == 15? You know, Chris, it occurs to me that perhaps Roy was thinking that "0xf" was somehow expressing a REPRESENTATION rather than a VALUE. Even though most code that uses such constants in bitwise operations might make that appear plausible, in actuality the decimal, octal, and hexadecimal constants are merely alternate ways of expressing the same thing, namely the value. (There is some effect on the type too, but that's not relevant to this discussion.) A standard-conforming C implementation must ensure that the bitwise operators produce the same results as the "obvious" implementation on a simple architecture would, but it can use any manner of gyrations in order to accomplish the right effect. In particular, it doesn't have to "really" represent integers in the "obvious" way, so long as it always acts as though it did when required. In practice, nearly all C implementations will be on binary-based architectures, and will use one of the following integral representations, depending on what the architecture provides the best support for: two's complement one's complement sign, magnitude The C standard supports efficient use of any of these three. For other representation schemes, e.g. decimal-based, at least the bitwise operators (including shift operators) will have to be implemented with additional code to in effect convert the operands to a "binary numeration system" basis before performing the operations.