From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,95db39b88fd27b40 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-23 08:41:14 PST Message-ID: <3CED0C3F.637A52D8@spamtrap.baesystems.com> Date: Thu, 23 May 2002 16:35:27 +0100 From: David Gillon Organization: BAE Systems Avionics X-Mailer: Mozilla 4.73 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Convert array to integer value References: <3ced014d$1@pull.gecm.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: rc3284.rochstr.gmav.gecm.com X-Trace: pull.gecm.com 1022168127 rc3284.rochstr.gmav.gecm.com (23 May 2002 16:35:27 +0100) Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!btnet-peer!btnet-peer0!btnet-feed5!btnet!newreader.ukcore.bt.net!pull.gecm.com!not-for-mail Xref: archiver1.google.com comp.lang.ada:24584 Date: 2002-05-23T16:35:27+01:00 List-Id: 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