comp.lang.ada
 help / color / mirror / Atom feed
From: njb@res.eng.uiowa.edu (Nate Bohlmann)
Subject: Re: Help with type conversion needed
Date: 1996/01/09
Date: 1996-01-09T00:00:00+00:00	[thread overview]
Message-ID: <4cuml0$11ro@flood.weeg.uiowa.edu> (raw)
In-Reply-To: dewar.821197198@schonberg

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




      parent reply	other threads:[~1996-01-09  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4ckmb7$vo0@flood.weeg.uiowa.edu>
     [not found] ` <DKrJpC.9HE.0.-s@inmet.camb.inmet.com>
     [not found]   ` <4cnivs$m1k@flood.weeg.uiowa.edu>
1996-01-08  0:00     ` Help with type conversion needed Tucker Taft
     [not found]     ` <dewar.821029372@schonberg>
1996-01-08  0:00       ` Nate Bohlmann
1996-01-08  0:00         ` Robert Dewar
1996-01-08  0:00           ` Keith Thompson
1996-01-09  0:00         ` Geert Bosch
     [not found]           ` <dewar.821197198@schonberg>
1996-01-09  0:00             ` Nate Bohlmann [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox