|
Prev: Ravenscar - program termination
Next: in defense of GC
From: frikk on 30 Jan 2007 10:51 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? 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
From: Dmitry A. Kazakov on 30 Jan 2007 11:37 On 30 Jan 2007 07:51:47 -0800, frikk wrote: > 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? Only if you could be sure about the format. But there is a portable way to do such things. You read 4 octets. From them (you should know the endianness of the machine that wrote the file) take the sign bit, take the biased exponent, take the mantissa (as an integer). The mantissa will probably have a hidden bit. (I don't know what for format Basic uses.) After that use T'Compose to produce the number of floating-point T. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Jean-Pierre Rosen on 30 Jan 2007 11:55 frikk a �crit : > 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). Hmm... This looks like a fixed point representation, not a floating point one. > 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? In general, Unchecked_Conversion is your friend when you need two different views, at differing levels of abstraction, of the same data. > Basically I need to be able to read in the binary data byte by byte > but store it into a 32 bit Float. However, if you do an unchecked_conversion to Float, it will certainly not work, because your data don't look at all like floats! -- --------------------------------------------------------- J-P. Rosen (rosen(a)adalog.fr) Visit Adalog's web site at http://www.adalog.fr
From: Ali Bendriss on 30 Jan 2007 12:35 On Tuesday 30 January 2007 16:55, Jean-Pierre Rosen wrote: > frikk a écrit : > > 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). > > Hmm... This looks like a fixed point representation, not a floating > point one. > There is the same kind of representation in the tiff format, The "type RATIONAL" two LONGs : the first represent the numerator of the fraction, the second the denominator. > > 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? > > In general, Unchecked_Conversion is your friend when you need two > different views, at differing levels of abstraction, of the same data. > I remember doing some Unchecked_Conversion to read a proprietary tiff file some time ago. But only to find the LONGs and then after I was just doing a simple division to get the result. > > Basically I need to be able to read in the binary data byte by byte > > but store it into a 32 bit Float. > It may be helpfull to know some value in advance like a magic number. > However, if you do an unchecked_conversion to Float, it will certainly > not work, because your data don't look at all like floats! -- Ali
From: Jeffrey R. Carter on 30 Jan 2007 12:56
frikk wrote: > > 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. Any reason you can't call this C function from Ada? -- Jeff Carter "I soiled my armor, I was so scared." Monty Python & the Holy Grail 71 |