From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: twin complement ...... Date: 18 Aug 2000 11:20:38 GMT Organization: Aachen University of Technology (RWTH) Lines: 21 Message-ID: <8nj666$bs8$1@nets3.rz.RWTH-Aachen.DE> References: <8ngqu9$fl8$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 966597638 12168 137.226.32.75 (18 Aug 2000 11:20:38 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 18 Aug 2000 11:20:38 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Florent 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.