* 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
* Re: Bit operations in Ada (one's complements and sum)
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
0 siblings, 1 reply; 4+ messages in thread
From: Ted Dennison @ 2000-09-09 0:01 UTC (permalink / raw)
ebresie@usa.net wrote:
> 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.
One's complement is just a "not" operation. You won't find a package to do
that, because it is too trivial of an operation for someone to make an
entire package out of. You just use the "not" operator on a packed array of
booleans or on a modular integer.
Some examples of this for unpacked arrays of boolean (aka: "Sets") are up on
AdaPower at http://www.adapower.com/lang/sets.html . But if you would like
to perform math operations on the same data without converting it, modular
integers would probably be better for you.
--
T.E.D.
Home - mailto:dennison@telepath.com Work - mailto:dennison@ssd.fsi.com
WWW - http://www.telepath.com/dennison/Ted/TED.html ICQ - 10545591
^ permalink raw reply [flat|nested] 4+ messages in thread
* Epistemology [was: Bit operations in Ada (one's complements and sum)]
2000-09-09 0:01 ` Ted Dennison
@ 2000-09-09 5:22 ` Nick Roberts
2000-09-09 20:18 ` Robert Dewar
0 siblings, 1 reply; 4+ messages in thread
From: Nick Roberts @ 2000-09-09 5:22 UTC (permalink / raw)
First, I wonder if Eric was talking about ones-complement arithmetic with
carry? If so, then (I think!) standard Ada doesn't have such an operation
explicitly built-in.
Second, forgive my musing on this subject, but it did just flicker across my
mind, that a 'bit string' is indeed a kind of string, but ... it's also a
set, but ... it's also an integer, but ... it's also a JPEG picture, but ...
well, you get the idea. Things are not what they are, are they? Just a
thought.
BTW probably "type Bit_String is private;" in the package spec.
--
Nick Roberts
http://www.AdaOS.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Epistemology [was: Bit operations in Ada (one's complements and sum)]
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
0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 2000-09-09 20:18 UTC (permalink / raw)
In article <8pchk8$co01k$1@ID-25716.news.cis.dfn.de>,
"Nick Roberts" <nickroberts@callnetuk.com> wrote:
> Second, forgive my musing on this subject, but it did just
> flicker across my mind, that a 'bit string' is indeed a kind
> of string, but ... it's also a set, but ... it's also an
> integer, but ... it's also a JPEG picture, but ... well, you
> get the idea. Things are not what they are, are they? Just a
> thought.
Sounds like you have rediscovered the fundamental and important
distinction between storage structures and data structures :-)
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