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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2aaba1527862ef22 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 30 Jan 2007 21:53:48 -0600 From: "Steve" Newsgroups: comp.lang.ada References: <1170172307.292500.256090@m58g2000cwm.googlegroups.com> Subject: Re: Reading Float Data from a binary file into ada Date: Tue, 30 Jan 2007 19:54:07 -0800 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.20.111.245 X-Trace: sv3-JtD4PfBzR+vGcF34RlGQ+krJ52wnv4DZHAfo8wlkW7XsSsd0SnkuFOb/LQ8TFUbnWtnQNVStcglHnLO!wHlPflDRlztVjEvEwfc6WEnjPbv2IKyp3ZoXKwAtsQToJ42cAoSCoqwBad57+z71b0ngoPU056q9!OPpOyHLKGrzN0g== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:8756 Date: 2007-01-30T19:54:07-08:00 List-Id: "frikk" wrote in message news:1170172307.292500.256090@m58g2000cwm.googlegroups.com... > Hello everyone! I am having a problem that I would love some help > with. > > Essentially I was given a Visual Basic program that dumps a binary > configuration file with all of the variables in a set. The variables > are each 32 bit floats, with the first 16 bits being the integer part > and the second 16 bits being a representation of the fraction (I'm not > sure if this is stanard - but its just how VB dumps the data). The > binary dump is basically a copy of the way VB stores the data in > memory. I need to be able to use this data in ada. There is a C > counterpart to this that makes use of a 'union' to grab the data 1 > byte (8 bits) at a time, put them into a char array of size 4, then > use a 32 bit float to reference the data. Is there somehow I can do > this in ada as well? Your description of how the C counterpart works is inconsistant with the way you have described the data format in the file. If the C program is using a union to view the data as either a float or a 4 character array then it is very likely that the data is in fact stored in IEEE 754 floating point format. If you are using Microsoft's C compiler this is certainly the case. The following snippet contains the pieces you need to do the conversion. TYPE aByte IS MOD 256; FOR aByte'SIZE USE 8; TYPE aByteArray IS ARRAY( Positive RANGE <> ) OF aByte; PRAGMA PACK( aByteArray ); TYPE aFourBytes IS NEW aByteArray(1..4); FUNCTION Conv IS NEW Ada.Unchecked_Conversion( aFourBytes, float ); ... a : float; b : aFourBytes; ... a := Conv( b ) Use unchecked conversion to convert from a type that contains 4 bytes to the float value you're looking for. Regards, Steve (The Duck) > > Basically I need to be able to read in the binary data byte by byte > but store it into a 32 bit Float. The C union example above uses the > same memory address for the Float as it does for the size 4 char > array. I don't even know if the VB dump will correspond with the way > ada handles floats or not, but I'll worry about that later. > > I am also using Matlab/Simulink if that provides any additional tools > to use for debugging. > > Thank you for any help, > Blaine >