From: David Gillon <David.Gillon@spamtrap.baesystems.com>
Subject: Re: Convert array to integer value
Date: Thu, 23 May 2002 16:35:27 +0100
Date: 2002-05-23T16:35:27+01:00 [thread overview]
Message-ID: <3CED0C3F.637A52D8@spamtrap.baesystems.com> (raw)
In-Reply-To: 3ced014d$1@pull.gecm.com
Stephen Frackelton wrote:
> I have set up an array of integers, value 0..1, to simulate a word, 16 bits.
> I need to convert this array of 0's and 1's from the binary value to its
> corresponding integer value.
> is there any simple way of doing this ?
> All i can think of is for loop through the array and having a translation
> table for each position within the array, i.e if bit 5 = 1 then add 16 to
> total, if bit 6 = 1 then add 32 to total and so on.
> any other ideas ?
Without getting into questions over why you would want to use a
datastructure like that, try the following algorithm:
Sum = 0
For Count = 1 to 16
Sum = Sum + ((2 ** Count-1) * Integer_Array(Count))
(And there's also a perfectly good internal company newsgroup for Ada
questions)
--
David Gillon
next prev parent reply other threads:[~2002-05-23 15:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-23 14:49 Convert array to integer value Stephen Frackelton
2002-05-23 15:00 ` Nige
2002-05-23 15:27 ` Stephen Frackelton
2002-05-23 16:36 ` Stephen Leake
2002-05-23 15:35 ` David Gillon [this message]
2002-05-24 8:22 ` Stuart Palin
-- strict thread matches above, loose matches on Subject: below --
2002-05-23 16:49 Beard, Frank [Contractor]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox