Mail Archives: djgpp/2000/08/18/08:32:06
Florent <florent AT oih DOT rwth-aachen DOT de> wrote:
> Is there any fonctions for the twin complement ?
You cause quite some confusion, here, by using the wrong term. The
thing you're talking about is usually called 'two's-complement'. It's
the way negative numbers are represented in integers, on almost all
existing types of computers.
The problem you're having is that you assume the machine can *guess*
what type of data element you want to convert: a byte, a 16bit word,
or a 32bit one. Two's-complement is only defined with respect to a
fixed size of datatype. You can't calculcate it with 0x10 stored in an
'int' variable, and expect to get the value of a single-byte
two's-complement.
Actually, due to the way C evaluated integer expressions, you'll
always operate in int, or longer datatypes. So you'll have to mask to
your required 'target' datatype later.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -