comp.lang.ada
 help / color / mirror / Atom feed
* Bit manipulation in Ada
@ 1999-02-04  0:00 msnata
  1999-02-04  0:00 ` David C. Hoos, Sr.
  1999-02-04  0:00 ` bourguet
  0 siblings, 2 replies; 4+ messages in thread
From: msnata @ 1999-02-04  0:00 UTC (permalink / raw)


M. Suryanata
Phone: 022 674364
Bandung
Indonesia

Dear Sir,

I am still studying in Informatic Department at  Bandung Institute Technology.
For my thesis, I use Ada language in coding phase.
I am not familiar with Ada language  but I have to use it because it is one of
the requirements given to me by my Advisor.
I use alot of bit manipulations, such as: shift left "<<", XOR  "^" in C
language, for my project.
Does Ada language have these features or capabilities  ?

Thanks,
M.Suryanata
-------------------------
email: msnata@iptn.co.id

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Bit manipulation in Ada
  1999-02-04  0:00 Bit manipulation in Ada msnata
@ 1999-02-04  0:00 ` David C. Hoos, Sr.
  1999-02-04  0:00   ` Marin David Condic
  1999-02-04  0:00 ` bourguet
  1 sibling, 1 reply; 4+ messages in thread
From: David C. Hoos, Sr. @ 1999-02-04  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3629 bytes --]


msnata@iptn.co.id wrote in message <79bvb3$99p$1@nnrp1.dejanews.com>...
>M. Suryanata
>Phone: 022 674364
>Bandung
>Indonesia
>
>Dear Sir,
>
Following this message is the section from the Ada Language Reference
Manual, dealing with your question.

David C. Hoos, sr.

>I am still studying in Informatic Department at  Bandung Institute
Technology.
>For my thesis, I use Ada language in coding phase.
>I am not familiar with Ada language  but I have to use it because it is one
of
>the requirements given to me by my Advisor.
>I use alot of bit manipulations, such as: shift left "<<", XOR  "^" in C
>language, for my project.
>Does Ada language have these features or capabilities  ?
>
B.2 The Package Interfaces

1 Package Interfaces is the parent of several library packages that declare
types and other entities useful for interfacing to foreign languages. It
also contains some implementation-defined types that are useful across more
than one language (in particular for interfacing to assembly language).

Static Semantics

2 The library package Interfaces has the following skeletal declaration:

3 package Interfaces is
 pragma Pure(Interfaces);
4  type Integer_n is range �2**(n�1) .. 2**(n�1) � 1;  -- 2�s complement
5  type Unsigned_n is mod 2**n;
6  function Shift_Left  (Value : Unsigned_n; Amount : Natural) return
Unsigned_n;
 function Shift_Right (Value : Unsigned_n; Amount : Natural) return
Unsigned_n;
 function Shift_Right_Arithmetic (Value : Unsigned_n; Amount : Natural)
  return Unsigned_n;
 function Rotate_Left  (Value : Unsigned_n; Amount : Natural) return
Unsigned_n;
 function Rotate_Right (Value : Unsigned_n; Amount : Natural) return
Unsigned_n;
 ...
end Interfaces;

Implementation Requirements

7 An implementation shall provide the following declarations in the visible
part of package Interfaces:

8 � Signed and modular integer types of n bits, if supported by the target
architecture, for each n that is at least the size of a storage element and
that is a factor of the word size. The names of these types are of the form
Integer_n for the signed types, and Unsigned_n for the modular types;
9 � For each such modular type in Interfaces, shifting and rotating
subprograms as specified in the declaration of Interfaces above. These
subprograms are Intrinsic. They operate on a bit-by-bit basis, using the
binary representation of the value of the operands to yield a binary
representation for the result. The Amount parameter gives the number of bits
by which to shift or rotate. For shifting, zero bits are shifted in, except
in the case of Shift_Right_Arithmetic, where one bits are shifted in if
Value is at least half the modulus.

10 � Floating point types corresponding to each floating point format fully
supported by the hardware.

Implementation Permissions

11 An implementation may provide implementation-defined library units that
are children of Interfaces, and may add declarations to the visible part of
Interfaces in addition to the ones defined above.

Implementation Advice

12 For each implementation-defined convention identifier, there should be a
child package of package Interfaces with the corresponding name. This
package should contain any declarations that would be useful for interfacing
to the language (implementation) represented by the convention. Any
declarations useful for interfacing to any language on the given hardware
architecture should be provided directly in Interfaces.
13 An implementation supporting an interface to C, COBOL, or Fortran should
provide the corresponding package or packages described in the following
clauses.






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

* Re: Bit manipulation in Ada
  1999-02-04  0:00 Bit manipulation in Ada msnata
  1999-02-04  0:00 ` David C. Hoos, Sr.
@ 1999-02-04  0:00 ` bourguet
  1 sibling, 0 replies; 4+ messages in thread
From: bourguet @ 1999-02-04  0:00 UTC (permalink / raw)


In article <79bvb3$99p$1@nnrp1.dejanews.com>,
  msnata@iptn.co.id wrote:
> M. Suryanata
> Phone: 022 674364
> Bandung
> Indonesia
>
> Dear Sir,
>
> I am still studying in Informatic Department at  Bandung Institute Technology.
> For my thesis, I use Ada language in coding phase.
> I am not familiar with Ada language  but I have to use it because it is one of
> the requirements given to me by my Advisor.

We hope that after your thesis, you'll choose Ada because you like it.

> I use alot of bit manipulations, such as: shift left "<<", XOR  "^" in C
> language, for my project.
> Does Ada language have these features or capabilities  ?

C bit manipulations may be implemented in (at least) 3 ways in Ada:

1) (packed) array of boolean, if you are really manipulating bits.

2) representation clauses, if you want to extract fields

3) modular types, if you really need both an integer meaning and
bit manipulation. This is like unsigned numbers in C, but I would
recommand you consider the other 2 ways before... just because you
are less familiar with.

Yours,

-- Jean-Marc

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Bit manipulation in Ada
  1999-02-04  0:00 ` David C. Hoos, Sr.
@ 1999-02-04  0:00   ` Marin David Condic
  0 siblings, 0 replies; 4+ messages in thread
From: Marin David Condic @ 1999-02-04  0:00 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> 
> Following this message is the section from the Ada Language Reference
> Manual, dealing with your question.
> 
We might also observe that section 4.5.1 of the ARM could be useful in
this respect in that it provides for the logical operators on modular
and array types.

I'd like to observe that the original poster refers to using "a lot" of
bit manipulations and that this might suggest that the wrong approach is
being taken. I've done some "bit twiddling" down at the hardware
interface level of various systems, but it has always been fairly
isolated and a small part of the overall system. I've also seen C
programmers performing bit manipulations to achieve effects that in
other languages (like Ada) have simpler expressions. It is typically
done because that is "The C Way" of handling things, but to do it
identically in Ada may be avoiding "The Ada Way" of doing business.

Obviously, if you need the bit manipulation it is there. But it isn't
always the most straightforward expression if your language is Ada.

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669
***To reply, remove "bogon" from the domain name.***

"Government is not reason. It is not eloquence. It is a force. 
Like fire, a dangerous servant and a fearful master."

    --  George Washington




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

end of thread, other threads:[~1999-02-04  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-04  0:00 Bit manipulation in Ada msnata
1999-02-04  0:00 ` David C. Hoos, Sr.
1999-02-04  0:00   ` Marin David Condic
1999-02-04  0:00 ` bourguet

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