comp.lang.ada
 help / color / mirror / Atom feed
From: ebresie@usa.net
Subject: Bit operations in Ada (one's complements and sum)
Date: Fri, 08 Sep 2000 23:34:03 GMT
Date: 2000-09-08T23:34:03+00:00	[thread overview]
Message-ID: <8pbt1a$vo8$1@nnrp1.deja.com> (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.



             reply	other threads:[~2000-09-08 23:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-08 23:34 ebresie [this message]
2000-09-09  0:01 ` Bit operations in Ada (one's complements and sum) 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
replies disabled

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