comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Fortran 95: How do you write code to do this?
Date: Fri, 2 Nov 2018 09:41:13 +0100
Date: 2018-11-02T09:41:13+01:00	[thread overview]
Message-ID: <prh2j8$19ct$1@gioia.aioe.org> (raw)
In-Reply-To: daf8b6e6-a5e1-4a63-8102-241913eac531@googlegroups.com

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

  reply	other threads:[~2018-11-02  8:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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