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: njb@res.eng.uiowa.edu (Nate Bohlmann) Subject: Re: Help with type conversion needed Date: 1996/01/09 Message-ID: <4cuml0$11ro@flood.weeg.uiowa.edu>#1/1 X-Deja-AN: 134548789 distribution: world references: <4ckmb7$vo0@flood.weeg.uiowa.edu> <4cnivs$m1k@flood.weeg.uiowa.edu> <4cq6ku$l5a@flood.weeg.uiowa.edu> <4cseli$epa@fozzie.sun3.iaf.nl> organization: University of Iowa, Iowa City, IA, USA newsgroups: comp.lang.ada Date: 1996-01-09T00:00:00+00:00 List-Id: First of all, let me thank everyone who has been trying to help with this problem. This is an area of Ada I am not well versed in at all and I appreciate the willingness to wade through a poorly specified problem. Robert Dewar (dewar@cs.nyu.edu) wrote: : Geert suggests : function To_Unsigned_16_B(S : Signed_16) return Unsigned_16 is : type Modular_16 is mod 2**16; : function To_Modular is : new Unchecked_Conversion(Signed_16, Modular_16); : function To_Unsigned is : new Unchecked_Conversion(Modular_16, Unsigned_16); : begin : return To_Unsigned(To_Modular(S) xor 16#8000#); : end To_Unsigned_16_B; : I find the use of xor obscure here, and it illustrates a danger of making : such logical operations available, they tend to get overused. : In the logical statement of the problem, the issue is to add 32768 to the : result, so it is much clearer to write: : return To_Unsigned (To_Modular(S) + 32_768); After twiddling with the bits, I now understand why this works.. :-) Thanks again to everyone who helped out on this.. Nate -- Nathan Bohlmann preferred-> njb@res.eng.uiowa.edu Computer Engineering Graduate Student njb@vu-alumni.elfwerks.com University of Iowa, Iowa City, IA njb@eng.uiowa.edu use PH at uiowa.edu for more info.. (319)354-2634 Dr. Alan Keyes for President! '96 http://sandh.com/keyes/index.html http://vu-alumni.elfwerks.com/~njb