comp.lang.ada
 help / color / mirror / Atom feed
* Bit operations in Ada (one's complements and sum)
@ 2000-09-08 23:34 ebresie
  2000-09-09  0:01 ` Ted Dennison
  0 siblings, 1 reply; 4+ messages in thread
From: ebresie @ 2000-09-08 23:34 UTC (permalink / raw)


I am curious if there exists either built in or already developed
somewhere, a bit manipulation package.

I am trying to have 16-bit numbers that are made into one's complement
and have one's complement summation occur with the values.

I started working on some of it, but thought I would check to see if
maybe this functionality already exists somewhere in ADA95 or exists
somewhere (one of the things about ADA is reusablility right :-)

I am not an expert of package development so any help would be
appreciated.

I started thinking that I would have something along the lines of:

package Bits is

-- I was thinking of using an array of Booleans but wasn't sure if this
-- was the most efficient way of working with Bits.
   type BIT_String is new String;
   type Ones_Complement is new BIT_String;
   type Twos_Complement is new BIT_String;

   function Ones_Complement( N : Integer ) return BIT_String;
   function Twos_Complement( N : Integer ) return BIT_String;
   function "+"( Left: Ones_Complement; Right : Twos_Complement ) return
Ones_Complement;
   function "+"( Left: Twos_Complement; Right : Twos_Complement ) return
Twos_Complement;

end Bits

The implementation I haven't completed yet...but figured I would check
with you guys first.

The implementation basically would take the Integer, check for negative
value, store a 1 for negative/0 for postive, then div/mod by two to get
each bit place.

I guess I should be able to somehow make this seperate from the
data type Integer and make it more abstract...how is the best way to do
that?

I am I just making this harder then I need to?

Any help would be appreciated

Eric Bresie
ebresie@usa.net


Sent via Deja.com http://www.deja.com/
Before you buy.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-09-09 20:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-08 23:34 Bit operations in Ada (one's complements and sum) ebresie
2000-09-09  0:01 ` Ted Dennison
2000-09-09  5:22   ` Epistemology [was: Bit operations in Ada (one's complements and sum)] Nick Roberts
2000-09-09 20:18     ` Robert Dewar

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