comp.lang.ada
 help / color / mirror / Atom feed
* Fortran 95: How do you write code to do this?
@ 2018-11-01  5:34 Michael_Smith@gmail.com
  2018-11-01  7:13 ` Petter Fryklund
  2018-11-02  9:05 ` Anatoly Chernyshev
  0 siblings, 2 replies; 12+ messages in thread
From: Michael_Smith@gmail.com @ 2018-11-01  5:34 UTC (permalink / raw)


Can you share with me both a simple program to do the following and also the best program imaginable? Please explain to me everything I need to know about the program!

1) Define a natural integer of n bits. Where n is some value such as 10 or 12.

2) Set the value of a boolean variable to the rightmost bit of this natural n-bit integer.

3) Shift the n-bit natural integer once left.

Repeat steps 2 and 3, for n different boolean variables.

Thanks,
Michael




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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01  5:34 Fortran 95: How do you write code to do this? Michael_Smith@gmail.com
@ 2018-11-01  7:13 ` Petter Fryklund
  2018-11-01  7:18   ` Petter Fryklund
  2018-11-01  7:54   ` Simon Wright
  2018-11-02  9:05 ` Anatoly Chernyshev
  1 sibling, 2 replies; 12+ messages in thread
From: Petter Fryklund @ 2018-11-01  7:13 UTC (permalink / raw)


Assuming rightmost means LSB:

generic 
  type T is mod <>;
function Boolean_Of(Nat : T) return Boolean;

function Boolean_Of(Nat : T) return Boolean is
begin
  return (Nat and 1) = 1;
end Boolean_Of;

type Ten_Bits is 2 ** 10;

function Boolean_Of_Ten_Bits is new Boolean_Of(Ten_Bits);

Input : Ten_Bits := 75;
Bool  : Boolean  := Boolean_Of_Ten_Bits(Input); -- will be True

regards,
Petter


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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01  7:13 ` Petter Fryklund
@ 2018-11-01  7:18   ` Petter Fryklund
  2018-11-01 16:35     ` Michael_Smith@gmail.com
  2018-11-01  7:54   ` Simon Wright
  1 sibling, 1 reply; 12+ messages in thread
From: Petter Fryklund @ 2018-11-01  7:18 UTC (permalink / raw)


Sorry, forgot about step 3: Shifting is available for modular types:

with Interfaces;
....
Interfaces.Shift_Left(Input);

Regards,
Petter


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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01  7:13 ` Petter Fryklund
  2018-11-01  7:18   ` Petter Fryklund
@ 2018-11-01  7:54   ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Simon Wright @ 2018-11-01  7:54 UTC (permalink / raw)


Petter Fryklund <petter.fryklund@atero.se> writes:

> type Ten_Bits is 2 ** 10;

type Ten_Bits is mod 2 ** 10;

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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01  7:18   ` Petter Fryklund
@ 2018-11-01 16:35     ` Michael_Smith@gmail.com
  2018-11-01 17:59       ` Jacob Sparre Andersen
  0 siblings, 1 reply; 12+ messages in thread
From: Michael_Smith@gmail.com @ 2018-11-01 16:35 UTC (permalink / raw)


On Thursday, November 1, 2018 at 3:18:09 AM UTC-4, Petter Fryklund wrote:
> with Interfaces;
> ....
> Interfaces.Shift_Left(Input);
> 

The Package Interfaces is listed on page B.1 (page 33) in "Lecture Notes in Computer Science 1246 Ada 95 Reference Manual Language and Standard Libraries."

Question 1: Is there a title of a book that you can give me that describes how to use the above book intelligently? 

Question 2: Is there a way to solve this problem without using Interfaces.Shift_Left ()?

Thanks 
Michael Smith



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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01 16:35     ` Michael_Smith@gmail.com
@ 2018-11-01 17:59       ` Jacob Sparre Andersen
  2018-11-02  6:19         ` Petter Fryklund
  0 siblings, 1 reply; 12+ messages in thread
From: Jacob Sparre Andersen @ 2018-11-01 17:59 UTC (permalink / raw)


"Michael_Smith@gmail.com" <ashos.owner@gmail.com> writes:

> The Package Interfaces is listed on page B.1 (page 33) in "Lecture
> Notes in Computer Science 1246 Ada 95 Reference Manual Language and
> Standard Libraries."
>
> Question 1: Is there a title of a book that you can give me that
> describes how to use the above book intelligently?

One option is "Programming in Ada 2012" by John Barnes.  It is a bit
long, but it should give you a pretty good understanding of Ada.

> Question 2: Is there a way to solve this problem without using
> Interfaces.Shift_Left ()?

Yes.  You could for example use modulus and multiply instead.

Greetings,

Jacob
-- 
"The point is that I am now a perfectly safe penguin!"

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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01 17:59       ` Jacob Sparre Andersen
@ 2018-11-02  6:19         ` Petter Fryklund
  2018-11-02  6:33           ` Petter Fryklund
  0 siblings, 1 reply; 12+ messages in thread
From: Petter Fryklund @ 2018-11-02  6:19 UTC (permalink / raw)


Wouldn't MSB fall of the edge when you multiply?

Also, why would like not to shift?


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

* Re: Fortran 95: How do you write code to do this?
  2018-11-02  6:19         ` Petter Fryklund
@ 2018-11-02  6:33           ` Petter Fryklund
  2018-11-02  8:41             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 12+ messages in thread
From: Petter Fryklund @ 2018-11-02  6:33 UTC (permalink / raw)


Without shift can be:

-- Counting bits from right to left, starting with zero
generic 
  type T is mod <>; 
function Boolean_Of(Nat : T; Bit_Number : Natural) return Boolean; 

function Boolean_Of(Nat : T; Bit_Number : Natural) return Boolean is 
begin 
  return (Nat and T(2 ** Bit_Number)) = 1; 
end Boolean_Of; 

type Ten_Bits is mod 2 ** 10; 

function Boolean_Of_Ten_Bits is new Boolean_Of(Ten_Bits); 

Input : Ten_Bits := 75; 
Bool1  : Boolean  := Boolean_Of_Ten_Bits(Input, 0); -- will be True 
Bool2  : Boolean  := Boolean_Of_Ten_Bits(Input, 1); -- will be False 

Regards,
Petter

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

* Re: Fortran 95: How do you write code to do this?
  2018-11-02  6:33           ` Petter Fryklund
@ 2018-11-02  8:41             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 12+ messages in thread
From: Dmitry A. Kazakov @ 2018-11-02  8:41 UTC (permalink / raw)


On 2018-11-02 07:33, Petter Fryklund wrote:
> Without shift can be:
> 
> -- Counting bits from right to left, starting with zero
> generic
>    type T is mod <>;
> function Boolean_Of(Nat : T; Bit_Number : Natural) return Boolean;
> 
> function Boolean_Of(Nat : T; Bit_Number : Natural) return Boolean is
> begin
>    return (Nat and T(2 ** Bit_Number)) = 1;
> end Boolean_Of;
> 
> type Ten_Bits is mod 2 ** 10;
> 
> function Boolean_Of_Ten_Bits is new Boolean_Of(Ten_Bits);
> 
> Input : Ten_Bits := 75;
> Bool1  : Boolean  := Boolean_Of_Ten_Bits(Input, 0); -- will be True
> Bool2  : Boolean  := Boolean_Of_Ten_Bits(Input, 1); -- will be False

BTW, this does not make sense unless T is mod 2**N and the compiler uses 
a certain representation for T.

In general, bit representation can be any. The number could be kept 
packed-decimal or as an EBCDIC string containing English numerals 
written right to left...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: Fortran 95: How do you write code to do this?
  2018-11-01  5:34 Fortran 95: How do you write code to do this? Michael_Smith@gmail.com
  2018-11-01  7:13 ` Petter Fryklund
@ 2018-11-02  9:05 ` Anatoly Chernyshev
  2018-11-02  9:14   ` gautier_niouzes
  2018-11-02 14:37   ` Dennis Lee Bieber
  1 sibling, 2 replies; 12+ messages in thread
From: Anatoly Chernyshev @ 2018-11-02  9:05 UTC (permalink / raw)


The problem statement looks like a homework assignment...


On Thursday, November 1, 2018 at 6:34:25 PM UTC+13, Michae...@gmail.com wrote:
> Can you share with me both a simple program to do the following and also the best program imaginable? Please explain to me everything I need to know about the program!
> 
> 1) Define a natural integer of n bits. Where n is some value such as 10 or 12.
> 
> 2) Set the value of a boolean variable to the rightmost bit of this natural n-bit integer.
> 
> 3) Shift the n-bit natural integer once left.
> 
> Repeat steps 2 and 3, for n different boolean variables.
> 
> Thanks,
> Michael

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

* Re: Fortran 95: How do you write code to do this?
  2018-11-02  9:05 ` Anatoly Chernyshev
@ 2018-11-02  9:14   ` gautier_niouzes
  2018-11-02 14:37   ` Dennis Lee Bieber
  1 sibling, 0 replies; 12+ messages in thread
From: gautier_niouzes @ 2018-11-02  9:14 UTC (permalink / raw)


Obviously.
Plus, chances are that it was posted in the wrong forum :-)...


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

* Re: Fortran 95: How do you write code to do this?
  2018-11-02  9:05 ` Anatoly Chernyshev
  2018-11-02  9:14   ` gautier_niouzes
@ 2018-11-02 14:37   ` Dennis Lee Bieber
  1 sibling, 0 replies; 12+ messages in thread
From: Dennis Lee Bieber @ 2018-11-02 14:37 UTC (permalink / raw)


On Fri, 2 Nov 2018 02:05:33 -0700 (PDT), Anatoly Chernyshev
<achernyshev@gmail.com> declaimed the following:

>The problem statement looks like a homework assignment...
>
	Especially when the subject line also states FORTRAN 95!


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/ 


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

end of thread, other threads:[~2018-11-02 14:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01  5:34 Fortran 95: How do you write code to do this? Michael_Smith@gmail.com
2018-11-01  7:13 ` Petter Fryklund
2018-11-01  7:18   ` Petter Fryklund
2018-11-01 16:35     ` Michael_Smith@gmail.com
2018-11-01 17:59       ` Jacob Sparre Andersen
2018-11-02  6:19         ` Petter Fryklund
2018-11-02  6:33           ` Petter Fryklund
2018-11-02  8:41             ` Dmitry A. Kazakov
2018-11-01  7:54   ` Simon Wright
2018-11-02  9:05 ` Anatoly Chernyshev
2018-11-02  9:14   ` gautier_niouzes
2018-11-02 14:37   ` Dennis Lee Bieber

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