[Gambas-user] Hex string to float

nando nando_f at ...951...
Sun Dec 14 21:23:04 CET 2008


My apologies to all...I stand corrected for my mistake.
The i = &h3fd55555& converts hex to integer and is easiest to do it this way.
This method does performs as the original person wanted but is a waste
to do disk IO.  Perhaps a pipe, write the integer, read the single.
Although I haven't investigated, Gambas3 has pointers.
Copying 4B from a pointer to the 4B int to the 4B single will do it. 
There are (older) versions of BASIC that had (something like) MKI$, MKS$, MKD$
and counterparts (something like) CVI, CVS, CVD.  They took a string and converted
it to an Int Single Double.  No conversion happened because the string was binary
correct for the type. All it did was copy 2B, 4B 8B from/to a numeric var to/from
string.
 If Benoit were to incorporate these functions, it makes Gambas easily perform IO of 
data types with ease to convert to native variables.
Thanks,
-Fernando


---------- Original Message -----------
From: Doriano Blengino <doriano.blengino at ...1909...>
To: nando_f at ...951..., mailing list for gambas users
<gambas-user at lists.sourceforge.net>
Sent: Sat, 13 Dec 2008 20:05:54 +0100
Subject: Re: [Gambas-user] Hex string to float

> nando ha scritto:
> > I'm sorry, but I cannot see this as correct.
> > Saving a 4 byte value in integer format then
> > reading in the same 4 byte value and place it in an float variable
> > performs no conversion.
> > Conversion is needed due to how we want to interpret the type of data.
> >   
> Indeed it does (perhaps a different syntax should be used - the one 
> which writes in binary format). The problem is that it is easy to write 
> an integer constant in the correct form (&h...); different is the case 
> when you read them from somewhere - they can have a different byte order 
> or format (in this case you can manipulate them).
> 
> Another problem is to use a file for doing this - this is a great waste 
> of resources; gambas has pointers too, but they are difficult to use.
> 
> Regards,
> Doriano
> >
> >
> > ---------- Original Message -----------
> > From: hjherbert at ...20...
> > To: gambas-user at lists.sourceforge.net
> > Sent: Sat, 13 Dec 2008 17:21:39 +0100
> > Subject: Re: [Gambas-user] Hex string to float
> >
> >   
> >> ... For 32 Float use the "Single" data type.
> >> See http://gambasdoc.org/help/cat/datatypes
> >> See http://gambasdoc.org/help/lang/type/single
> >>
> >> The example conversion may be done by this way:
> >>
> >> PUBLIC SUB DemoSingle()
> >> DIM i AS Integer
> >> DIM f AS Single
> >> DIM hH AS File
> >>
> >> i = &h3fd55555&
> >> OPEN "/tmp/hexfloat.tmp" FOR WRITE CREATE AS #hH
> >> WRITE #hH, i
> >> CLOSE #hH
> >> OPEN "/tmp/hexfloat.tmp" FOR READ AS #hH
> >> READ #hH, f
> >> CLOSE #hH
> >> PRINT "i=", i, "HEX", Hex$(i), "  f=", f
> >> END
> >>
> >> ------------------------------------------------------------------------------
> >> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> >> The future of the web can't happen without you.  Join us at MIX09 to help
> >> pave the way to the Next Web now. Learn more and register at
> >> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> >> _______________________________________________
> >> Gambas-user mailing list
> >> Gambas-user at lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> >>     
> > ------- End of Original Message -------
> >
> >
> > ------------------------------------------------------------------------------
> > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> > The future of the web can't happen without you.  Join us at MIX09 to help
> > pave the way to the Next Web now. Learn more and register at
> > http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> 
> -- 
> Doriano Blengino
> 
> "Listen twice before you speak.
> This is why we have two ears, but only one mouth."
> 
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list