Hexadecimal/octal constants
Dan Bernstein
brnstnd at kramden.acf.nyu.edu
Thu Mar 21 07:59:49 AEST 1991
In article <RJOHNSON.91Mar20091144 at olorin.shell.com> rjohnson at shell.com (Roy Johnson) writes:
> Is it true on every platform that 0xf == 15?
Yes.
> Is it also true on every platform that for bitwise operations, C
> behaves as if it is on a two's complement machine, so that, e.g., the
> result of 0xf & 0x2 is 0x2,
Yes, the result of 0xf & 0x2 is 0x2. No, C does not ``behave as if it is
on a two's complement machine'' for bitwise operations: two's complement
has to do with the representation of negatives, and the bit operators
basically treat everything as unsigned. (Apparently ANSI implies that
any implementation must be one's-complement or two's-complement, but
this is beside the point.)
C does behave as if it is on a binary machine when it is working with
binary digits, even if it is on a base-10 machine or whatever else.
> even if the machine representation of
> 0xf is 1010 and 0x2 is 0101 [think hypothetical here 8^)]?
BEEP! :-) The machine representation is irrelevant. ``If the machine
represents 2 as 0101 and 5 as 1010, does 2 + 2 equal 5?''
---Dan
More information about the Comp.lang.c
mailing list