comp.lang.ada
 help / color / mirror / Atom feed
* Bitwise operators
@ 2001-03-29 18:54 Bob Gratton
  2001-03-29 19:03 ` chris.danx
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Bob Gratton @ 2001-03-29 18:54 UTC (permalink / raw)


Are there any bitwise operators in ADA? I'd like to compare two binary
numbers with AND and OR... Is it possible?

Thanx!






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

* Re: Bitwise operators
  2001-03-29 18:54 Bitwise operators Bob Gratton
@ 2001-03-29 19:03 ` chris.danx
  2001-03-30 14:50   ` Ted Dennison
  2001-03-30  6:54 ` Martin Dowie
  2001-03-30 12:56 ` Marc A. Criley
  2 siblings, 1 reply; 10+ messages in thread
From: chris.danx @ 2001-03-29 19:03 UTC (permalink / raw)


There are none in ADA but there are in Ada!

Ada has XOR, NOT, OR, AND,

i'm not sure which types you can use them on, but i know boolean and mod
types, and maybe integers support them.


Chris Campbell


"Bob Gratton" <bobby@sympatico.ca> wrote in message
news:qxLw6.488391$Pm2.7613079@news20.bellglobal.com...
> Are there any bitwise operators in ADA? I'd like to compare two binary
> numbers with AND and OR... Is it possible?
>
> Thanx!
>
>
>





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

* Re: Bitwise operators
  2001-03-29 18:54 Bitwise operators Bob Gratton
  2001-03-29 19:03 ` chris.danx
@ 2001-03-30  6:54 ` Martin Dowie
  2001-03-30 12:56 ` Marc A. Criley
  2 siblings, 0 replies; 10+ messages in thread
From: Martin Dowie @ 2001-03-30  6:54 UTC (permalink / raw)


Check out the spec of package Interfaces (section B.2 of the RM). In there
are
all sort of mod (modular) numbers (i.e. unsigned numbers that wrap rather
than
raise exceptions). You'll find shift subprograms there too - the
"and"/"or"/etc
operators are implicit for modular types.


Bob Gratton <bobby@sympatico.ca> wrote in message
news:qxLw6.488391$Pm2.7613079@news20.bellglobal.com...
> Are there any bitwise operators in ADA? I'd like to compare two binary
> numbers with AND and OR... Is it possible?
>
> Thanx!
>
>
>





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

* Re: Bitwise operators
  2001-03-29 18:54 Bitwise operators Bob Gratton
  2001-03-29 19:03 ` chris.danx
  2001-03-30  6:54 ` Martin Dowie
@ 2001-03-30 12:56 ` Marc A. Criley
  2001-03-30 14:39   ` Marin David Condic
  2 siblings, 1 reply; 10+ messages in thread
From: Marc A. Criley @ 2001-03-30 12:56 UTC (permalink / raw)


Bob Gratton wrote:
> 
> Are there any bitwise operators in ADA? I'd like to compare two binary
> numbers with AND and OR... Is it possible?
> 
> Thanx!

Most definitely!

One of the primary uses of modular types is in support of logical
operations.  Here's a little program that illustrates their use:

with Text_IO; use Text_IO;

procedure Mod_Demo is

   type A_Modular_Type is mod 2**16;

   A : A_Modular_Type := 511;
   B : A_Modular_Type := 255 * 256;

begin
   Put_Line("A and B =" & A_Modular_Type'Image(A and B));
   Put_Line("A or  B =" & A_Modular_Type'Image(A or  B));
   Put_Line("A xor B =" & A_Modular_Type'Image(A xor B));
end Mod_Demo;

For more info on modular types, see section 3.5.4 of the Ada Reference
Manual (which covers all the "integer" types), and 4.5.1 for info on how
modular types are operated on by the logical operators.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



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

* Re: Bitwise operators
  2001-03-30 12:56 ` Marc A. Criley
@ 2001-03-30 14:39   ` Marin David Condic
  0 siblings, 0 replies; 10+ messages in thread
From: Marin David Condic @ 2001-03-30 14:39 UTC (permalink / raw)


IIRC, you also get logical operations on arrays of Boolean - this can be
very useful as well - especially if the array is packed into a convenient
machine word size. (See ARM 4.5.1(2..6), etc.) It is handy when you want to
set specific bits in the word as well as performing logical operations
between words. Of course, the relative efficiency of this is going to be
compiler dependent. Some may properly degenerate it to single machine
instructions whereas others may go around the block a few times. YMMV.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/



"Marc A. Criley" <mcqada@earthlink.net> wrote in message
news:3AC474DE.85E8B1A4@earthlink.net...
> Bob Gratton wrote:
> >
> > Are there any bitwise operators in ADA? I'd like to compare two binary
> > numbers with AND and OR... Is it possible?
> >
> > Thanx!
>
> Most definitely!
>
> One of the primary uses of modular types is in support of logical
> operations.  Here's a little program that illustrates their use:
>
> with Text_IO; use Text_IO;
>
> procedure Mod_Demo is
>
>    type A_Modular_Type is mod 2**16;
>
>    A : A_Modular_Type := 511;
>    B : A_Modular_Type := 255 * 256;
>
> begin
>    Put_Line("A and B =" & A_Modular_Type'Image(A and B));
>    Put_Line("A or  B =" & A_Modular_Type'Image(A or  B));
>    Put_Line("A xor B =" & A_Modular_Type'Image(A xor B));
> end Mod_Demo;
>
> For more info on modular types, see section 3.5.4 of the Ada Reference
> Manual (which covers all the "integer" types), and 4.5.1 for info on how
> modular types are operated on by the logical operators.
>
> Marc A. Criley
> Senior Staff Engineer
> Quadrus Corporation
> www.quadruscorp.com





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

* Re: Bitwise operators
  2001-03-29 19:03 ` chris.danx
@ 2001-03-30 14:50   ` Ted Dennison
  2001-03-30 21:05     ` Robert A Duff
  0 siblings, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2001-03-30 14:50 UTC (permalink / raw)


In article <3GLw6.1367$MZ2.275440@news2-win.server.ntlworld.com>, chris.danx
says...
>Ada has XOR, NOT, OR, AND,
>
>i'm not sure which types you can use them on, but i know boolean and mod
>types, and maybe integers support them.

Boolean, arrays of Boolean, and Modular types support them. Integers do not.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Bitwise operators
  2001-03-30 14:50   ` Ted Dennison
@ 2001-03-30 21:05     ` Robert A Duff
  2001-04-02 13:27       ` Ted Dennison
  0 siblings, 1 reply; 10+ messages in thread
From: Robert A Duff @ 2001-03-30 21:05 UTC (permalink / raw)


Ted Dennison<dennison@telepath.com> writes:

> Boolean, arrays of Boolean, and Modular types support them. Integers do not.

Modular types *are* integer types.

- Bob



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

* Re: Bitwise operators
  2001-03-30 21:05     ` Robert A Duff
@ 2001-04-02 13:27       ` Ted Dennison
  2001-04-02 14:44         ` Robert A Duff
  0 siblings, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2001-04-02 13:27 UTC (permalink / raw)


In article <wccwv97klvu.fsf@world.std.com>, Robert A Duff says...
>
>Ted Dennison<dennison@telepath.com> writes:
>
>> Boolean, arrays of Boolean, and Modular types support them. Integers do not.
>
>Modular types *are* integer types.

Clearly I meant things specified by the identifier *integer* or one of its
subtypes, not what the LRM (IMHO confusingly) refers to as integer types (which
includes modular types, as well as the type "integer"). Admittedly, the "proper"
LRM term for this is "signed integer type", but bringing up strict LRM
terminology in a beginner thread is only going to confuse the reader.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Bitwise operators
  2001-04-02 13:27       ` Ted Dennison
@ 2001-04-02 14:44         ` Robert A Duff
  2001-04-02 16:05           ` Ted Dennison
  0 siblings, 1 reply; 10+ messages in thread
From: Robert A Duff @ 2001-04-02 14:44 UTC (permalink / raw)


Newsgroups: comp.lang.ada
Subject: Re: Bitwise operators
References: <qxLw6.488391$Pm2.7613079@news20.bellglobal.com>
	<wccwv97klvu.fsf@world.std.com>
	<17%x6.222$UK4.21679@www.newsranger.com>
--text follows this line--
Ted Dennison<dennison@telepath.com> writes:

> 
> In article <wccwv97klvu.fsf@world.std.com>, Robert A Duff says...
> >
> >Ted Dennison<dennison@telepath.com> writes:
> >
> >> Boolean, arrays of Boolean, and Modular types support them. Integers do not.
> >
> >Modular types *are* integer types.

> Clearly I meant things specified by the identifier *integer* or one of
> its subtypes,

No, I think you meant "signed integer types".  This includes types
derived from Standard.Integer, and integer types declared the "usual"
way (ie, "type T is range A..B;"), which have nothing to do with the
identifier Integer.

>... not what the LRM (IMHO confusingly) refers to as integer
> types (which includes modular types, as well as the type
> "integer").

It's confusing to me, too.  But I suspect it's only confusing to you and
me because we learned Ada 83 first, where "integer type" refered to what
is now called "signed integer type".  True?

After all, both signed integer and modular types have mathematical
integers as their values.  So why shouldn't both be called integer
types?

>... Admittedly, the "proper" LRM term for this is "signed
> integer type", but bringing up strict LRM terminology in a beginner
> thread is only going to confuse the reader.

Sorry for all this nitpicking.  But I really don't agree that beginners
should be taught the wrong terminology.  It will only confuse them when
they try to read something about Ada (the RM or a text book).

Now I admit that I say "pointer" instead of "access type" or "access
value" when I'm talking informally about Ada programs.  But that doesn't
confuse -- pointers point at things, and there's no conflicting
definition of pointer in the Ada RM.  But there *is* a definitiion of
"integer type", so I think you will confuse people when you say "integer
type" to mean "signed integer type".

- Bob



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

* Re: Bitwise operators
  2001-04-02 14:44         ` Robert A Duff
@ 2001-04-02 16:05           ` Ted Dennison
  0 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 2001-04-02 16:05 UTC (permalink / raw)


In article <wccitknz7i6.fsf@world.std.com>, Robert A Duff says...
>Ted Dennison<dennison@telepath.com> writes:
>
>>... Admittedly, the "proper" LRM term for this is "signed
>> integer type", but bringing up strict LRM terminology in a beginner
>> thread is only going to confuse the reader.
>
>Sorry for all this nitpicking.  But I really don't agree that beginners
>should be taught the wrong terminology.  It will only confuse them when
>they try to read something about Ada (the RM or a text book).

That's fine, if its is adequately explained for the beginner. My worry is that
the original poster, who was clearly an Ada neophyte, is going to see someone
authoratatively say "you can use boolean ops on integers", quite reasonably go
out and try just that with something of type "Integer", and then get frustrated
when the compiler says they can't do that. If we tick them off in the early
stages, they won't hang around long enough to ever look in the LRM. :-)

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

end of thread, other threads:[~2001-04-02 16:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-29 18:54 Bitwise operators Bob Gratton
2001-03-29 19:03 ` chris.danx
2001-03-30 14:50   ` Ted Dennison
2001-03-30 21:05     ` Robert A Duff
2001-04-02 13:27       ` Ted Dennison
2001-04-02 14:44         ` Robert A Duff
2001-04-02 16:05           ` Ted Dennison
2001-03-30  6:54 ` Martin Dowie
2001-03-30 12:56 ` Marc A. Criley
2001-03-30 14:39   ` Marin David Condic

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