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.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no 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 09:51:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!freenix!enst!enst.fr!not-for-mail From: "Beard, Frank [Contractor]" Newsgroups: comp.lang.ada Subject: RE: Convert array to integer value Date: Thu, 23 May 2002 12:49:46 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: avanie.enst.fr 1022172664 13494 137.194.161.2 (23 May 2002 16:51:04 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Thu, 23 May 2002 16:51:04 +0000 (UTC) Return-Path: X-Mailer: Internet Mail Service (5.5.2650.21) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:24592 Date: 2002-05-23T12:49:46-04:00 Assuming you have your 16 bit integer defined something like the following: with Ada.Text_Io; with Ada.Unchecked_Conversion; procedure BitTest is type Word is range -2**15 .. 2**15-1; for Word'size use 16; type Bit is mod 2; for Bit'size use 1; type Bit_Array is array (1..16) of Bit; pragma Pack(Bit_Array); function To_Integer is new Ada.Unchecked_Conversion(Source => Bit_Array, Target => Word); bits : Bit_Array := (others => 0); result : Word := 0; char : character := ' '; begin --+ Results on Windows. Your order will --+ vary based on the bit order on your machine. --+ On Windows: High Order bit is index 16 --+ Low Order bit is index 1. --+ Running with the first two "bits" values below --+ will tell you immediately what you need to know. bits := (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); --+ -32768 -- bits := (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); --+ 1 -- bits := (1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0); --+ 7 result := To_Integer(bits); Ada.Text_Io.New_Line; Ada.Text_Io.Put_Line("Word [" & Word'image(result) & " ]"); Ada.Text_Io.New_Line; Ada.Text_Io.Put("Hit any key to continue ..."); Ada.Text_Io.Get_Immediate(char); end BitTest; Frank -----Original Message----- From: Stephen Frackelton [mailto:stephen.frackelton@baesystems.com] Sent: Thursday, May 23, 2002 10:49 AM To: comp.lang.ada@ada.eu.org Subject: Convert array to integer value 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 ? thanks Stephen _______________________________________________ comp.lang.ada mailing list comp.lang.ada@ada.eu.org http://ada.eu.org/mailman/listinfo/comp.lang.ada