From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bb791bffed99d85a X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Help with type conversion needed Date: 1996/01/08 Message-ID: #1/1 X-Deja-AN: 134430674 references: <4ckmb7$vo0@flood.weeg.uiowa.edu> <4cnivs$m1k@flood.weeg.uiowa.edu> <4cq6ku$l5a@flood.weeg.uiowa.edu> organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-01-08T00:00:00+00:00 List-Id: iNathan finally explains:: "Right, and this is why I don't want it to be a noop. If I have a range of values from -32768 to 32767, and I want to shift that range to 0 to 65535, simply doing a noop is NOT sufficient.. i.e. -32768 maps to 0 and 32767 maps to 65535. -1 should map to 32767, NOT 65535." In otherwords what he wants to do is not a type conversion at all, in that the result value is different from the input value. The algorithm is perfectly trivial Take your original signed value Uncheck convert to 16-bit modular add 32768 that's all there is to it! You do not need to use a larger type at all. Note that the addition of 32768 in modular arithmetic wraps just as you need it to, that is what modular arithmetic is all about!