Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




IEEE 754 Float Conversion


I need a little help with this one please.I need to read in a raw 32 bit floating point number from a file and turn it into useable data. A visual basic "single" data type is the same as a float in c/c++, but when I try to input or output a single in visual basic to a file it first turns it does an automatic ascii conversion. I need to be able to take the raw 4 byte binary number out of the file and turn it into a single.example :5.75 would be stored as 40 B8 00 00 hex in the file. I need to be able to take in the 4 byte code and get the 5.75 back.Thanks much for your help




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Help To Convert Byte Array To Ieee Float And Long Integer
Hi,

I'm reading bytes from a binary file in blocks of four bytes.
I now need to convert to ieee float and long integer

I have tried defining a variable as single concatenating bytes and converting by loading to a variable defined as a single,
I have also tried using Csng. I'm obviously missing a step
Here are the two blocks of bytes.
236, 81, 248, 64
205, 204, 0, 65

The results should be 7.76 and 8.05 for the float conversions
but how do I get there.

Thanks
Valter

Ieee To Single Conversion
I'm sure there is a simple solution so here goes: I have a 4 byte string representation of an ieee floating point number, how do I convert it to a VB single precision variable?

Float Conversion
Hi!

I have a string(a) which consists of a number(5) and a variable(z). I replace z with 2 using replace function.
and I want to get 7 as result(x). Is there any function to get right result.

CODEDim a As String
Dim x As Long
a = "(z + 5)"

a = Replace(a, "z", "2")
x = Val(a)

2 Float Part To Decimal Conversion
Hi,

This is my very first post on here so I hope I'm at least in the right section for my question. I really dont know much about VB programming I usualy program PLC in industries with a "VB like" language but even more simple

So here is my situation, I have an ActiveX that is polling an input value of one of my PLC to excel. The problem is that my PLC store this vallue in a float format in 2 16 bits register that I have to poll induvidually. So what I would need is to convert these 2 value in a single decimal format value of the input of my PLC.

Could someone give me some giude lines ?

Thank you!

Type Conversion Problem With (float)
Dears

I've been reading values from database MSSQL 2000 by recordset and if I got in
rs.Fields(4).Value for ex. 7,9

and I'm going to compare it with
rs3.Open "select my_value from my_records where dii_Values ='" & rs.Fields(4).Value & "'", conn, adOpenStatic, adLockReadOnly

then error is generated
Error converting data type varchar to float

How to convert it? having it as cdbl(rs.Fields(4).Value) or csng(rs.Fields(4).Value) is also the same

dii_Values is float 8 byte type column

Ieee 745
Hello,

Does anybody know how to read out/manually update the four bytes in an IEEE 745 single data type in Visual Basic? What I want to do is similar to the union of a float/4bytes in C.

Many thanks in advance

Kristian Winter

Getting 32 Bit IEEE
Im reading in my file through binary access.
How can i convert my 4bytes into IEEE format?

Thanks for any help.

Ieee 1394 Pci
hi all


Could some one help me..

to find sample codes for IEEE 1394 video editing.../
some tutorials for ieee 1394 for the same as i am new to this topic.

Thank you in advance

Rema

Double IEEE In Basic
Hi,

I've writen a program in qbasic to perform a specific task. Now, the problem is that the variable v (v1,v2,v3)must be not a single double ( 4 bytes ) but an IEEE double ( 8 bytes ) - the following programs force me to have the values in this format.
The code I've written is as follows:

CLS
DIM v AS DOUBLE
n = 0
ON ERROR GOTO 1000
OPEN "c:jpl408jpleph.408" FOR INPUT AS #1
OPEN "c:jpl408408.txt" FOR BINARY AS #2
r=SEEK (2)
DO UNTIL EOF(1)
LINE INPUT #1, a$
a$ = LTRIM$(a$)
v1 = 0: v2 = 0: v3 = 0
i = INSTR(1, a$, " ")
v1 = VAL(MID$(a$, 1, i - 1))
a$ = LTRIM$(MID$(a$, i + 1)): i = INSTR(1, a$, " ")
v2 = VAL(MID$(a$, 1, i - 1))
a$ = LTRIM$(MID$(a$, i + 1))
v3 = VAL(MID$(a$, 1))
i = INSTR(1, a$, "D")
IF i >= 1 THEN PUT #2, , v1
IF i >= 1 THEN PUT #2, , v2
IF i >= 1 THEN PUT #2, , v3: n = n + 1: LOCATE 1, 1: PRINT n
LOOP
CLOSE
END
1000 i = 0: RESUME NEXT



I think that this must be programed in Visual Basic. Another problem, is that the results overwriten the existing data in 408.txt

Can someone help me making the necessary changes? As always this is very urgent.

Regards,

Kepler

Sending #'s Out In 4 Byte IEEE 754 Form
I am trying to write a program in which I enter a number in a text box and then send the number in IEEE 754 format through the comm port (RS232) which would consist of 4 bytes obviously since IEEE 754 contains 32 characters. How can I do this? I also want to receive 4 bytes in IEEE 754 format and display it in a text box as well. I have constructed a RS232 cable that connects Pins 2 & 3 so I can immediately receive what I send so I can see if both sides are working. Also I monitor it with an oscilloscope to make sure I am sending it in the correct format. I ultimately have to send and receive data to and from another device that is currently sending and receiving in IEEE 754 format at 9600, no parity, 8 bits, 1 stop bit and no handshaking. Please help.

To Transform IEEE-P 754 80-bit Floating Point
Hallo experts!

I import the 80bits as string to VB. Is there a routine/function to transform the values to VB type "double". (of course by loss of precision) and vis versa.

Thanks and regards

Hans

IEEE Single ==> DEC Spfp Format
Does anyone have a function that converts IEEE single to DEC spfp format? Thank you.

??? How To Display IEEE 1394 Video In A GUI ???
Hello all,

I found the following visual basic 6.0 source code on the web for
displaying web cam video in a GUI. However, I want to display video
from a camera which is hooked up through firewire (IEEE 1394), not
USB. What portion of the code would I need to change in order to
achieve this?

Thanks in advance,
-Bill

---------------------------------------------------------

Option Explicit

Const ws_visible = &H10000000
Const ws_child = &H40000000
Const WM_USER = 1024
Const WM_CAP_EDIT_COPY = WM_USER + 30
Const wm_cap_driver_connect = WM_USER + 10
Const wm_cap_set_preview = WM_USER + 50
Const wm_cap_set_overlay = WM_USER + 51
Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Const WM_CAP_SEQUENCE = WM_USER + 62
Const WM_CAP_SINGLE_FRAME_OPEN = WM_USER + 70
Const WM_CAP_SINGLE_FRAME_CLOSE = WM_USER + 71
Const WM_CAP_SINGLE_FRAME = WM_USER + 72
Const DRV_USER = &H4000
Const DVM_DIALOG = DRV_USER + 100
Const PREVIEWRATE = 30

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll"
Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long,
ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As
Integer, ByVal g As Long, ByVal h As Integer) As Long

Dim hwndc As Long
Dim saveflag As Integer
Dim pictureindex As Integer
Dim filter1(-1 To 1, -1 To 1) As Single
Dim filter2(-1 To 1, -1 To 1) As Single
Dim temp As String

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
On Error GoTo handler:
hwndc = capCreateCaptureWindow("CaptureWindow", ws_child Or
ws_visible, 0, 0, PichWnd.Width, PichWnd.Height, PichWnd.hWnd, 0)
If (hwndc <> 0) Then
temp = SendMessage(hwndc, wm_cap_driver_connect, 0, 0)
temp = SendMessage(hwndc, wm_cap_set_preview, 1, 0)
temp = SendMessage(hwndc, WM_CAP_SET_PREVIEWRATE, PREVIEWRATE,
0)

temp = SendMessage(Me.hWnd, WM_CAP_EDIT_COPY, 1, 0)
Picture1.Picture = Clipboard.GetData
Else
MsgBox "Unable to capture video.", vbCritical
End If
Exit Sub
handler:
End
End Sub

Convert MB Binary Format Number To IEEE
Quick basic has a function CVSMBF to convert the old MS Binary format numbers to IEEE format numbers.


eg CVSMBF(highdata$)
The output being a single precision number eg 4.28
highdata$ being a 4byte string

I am coverting an old QB program to VB5

Sorry OnErrOr my previous query was missleading, what I really need is an answer to the above.

Convert Bytes To IEEE-754 Floating Point
I have 4 ordered bytes values (0-255) which I receive from a device's output. These 4 bytes represent a 32bit floating point value in IEEE-754 format. I need a VB6 function which converts the 4 bytes into this value. Thanks in advance.

IEEE Format For FLoating Point Calculations
hii,
how can i convert Text1.Text to Floating Variable using IEEE-754 Floating Point Conversion,
is there any ready made function?
Yogi

Converting Between IEEE Format (Single Precision) And Longs
Does anyone know if VB can now (VB6.0) perform a conversion between the internal representation of a single-precision number (held as a long, 4 bytes) and an actual Single? By this I mean, the value 1.0 as a Single = &h3F800000 internally. If I have a Long containing &h3F800000, is it possible to convert to a Single of 1.0, and vice versa (Single -> Long holding internal representation).

So far I have had to use a C DLL to do this.

Other possible ways to do this might involve using Variants, Byte arrays or some way of accessing the memory used to store the variables (used to be VARSEG and VAROFFSET in QuickBasic) - but I can't find a way.

Note that CLng(Single) and CSng(Long) don't do it, since CSng(&h3F800000) = 1065353216.0, which isn't quite 1.0 {:v)

Note also that you can't use Any as the type in your own functions {:v(

If anyone's wondering why I need this, it's to pull bytes out of a Modbus message and decode them, or to encode them and plug them into a message.

Capture Movie From Camcorder Over FireWire IEEE.1394
Is possible in Visual Basic capture movie from camcorder over IEEE.1394 ? If yes can you me help ???

Converting Between IEEE Format (Single Precision) And Longs
Does anyone know if VB can now (VB6.0) perform a conversion between the internal representation of a single-precision number (held as a long, 4 bytes) and an actual Single? By this I mean, the value 1.0 as a Single = &h3F800000 internally. If I have a Long containing &h3F800000, is it possible to convert to a Single of 1.0, and vice versa (Single -> Long holding internal representation).

So far I have had to use a C DLL to do this.

Other possible ways to do this might involve using Variants, Byte arrays or some way of accessing the memory used to store the variables (used to be VARSEG and VAROFFSET in QuickBasic) - but I can't find a way.

Note that CLng(Single) and CSng(Long) don't do it, since CSng(&h3F800000) = 1065353216.0, which isn't quite 1.0 {:v)

Note also that you can't use Any as the type in your own functions {:v(

If anyone's wondering why I need this, it's to pull bytes out of a Modbus message and decode them, or to encode them and plug them into a message.

VB6: How To Read Data From Binary File In IEEE Floating Point, Little-Endian Format?
I have a proprietary binary file here that contains a variable called 'Hydroxyl #', seven sample titles (2, 5, 9, 12, 20, 23, 31 - these titles could just as easily be text, so they are probably stored as strings), and the associated float values for the variable (44.94, 46.17, 51.93, 54.08, 61.62, 63.75, 84.77). I have attached the zipped data file in 'Polyvl.zip'.

Below, I have also pasted a Matlab script that a long-since departed member of our company wrote to read the file. The script uses the 'fopen' command with the 'ieee-le' option (IEEE Float-Point, Little-Endian, bits not explicity specified).

My question is, how do I properly read (and also, display) this data properly in Visual Basic 6? I am currently using the 'Open ... For Binary Access Read ...' statement and the 'Input' statement to read the data into a Variant type variable. I am able to grab some of the data (Hydroxl #), but the rest looks like garbage.

Contact me at DSanborn3@hotmail, or DSanborn3 (at AIM, MSN, Yahoo) with additional questions or comments. TIA!

Regards,

Daniel

//-----Begin Matlab Script (read_da.m)---------------

function [a,spl_name]=read_da(fn);
% READ_DA -- read NIR NSAS data files.
%
% [a,spl_name]=read_da('filename');
% or
% [a,spl_name]=read_da;
%
% Will not work for full Vis/NIR range.
% Works for spectra transferred from pc to rs/6000 via binary ftp.
%
% See read_fda for reading full Vis/NIR range.

if nargin==0,
[fn,pt]=uigetfile('*.da','Select NSAS *.da file');
fn = fullfile(pt,fn);
end

inp=fopen(fn,'r','ieee-le');

nspec=0;
k=fread(inp,128,'char');

fseek(inp,2944,-1);
%
% loop for reading sample names
%
while ~feof(inp)
nspec=nspec+1;
da=k(65)+k(66)*256;
mo=k(67)+k(68)*256;
yr=k(69)+k(70)*256;
hr=k(71)+k(72)*256;
mi=k(73)+k(74)*256;
se=k(75)+k(76)*256;
spl_name(nspec,1:30)=[setstr(k(5:14))' sprintf(' %2g:%2g:%2g %2g-%2g-%4g',hr,mi,se,mo,da,yr)];
k=fread(inp,128,'char');
fseek(inp,(nspec+1)*2944,-1);
end;

frewind(inp);
a=zeros(nspec,700);
for i=1:nspec
k=fread(inp,2944./4,'float');

a(i,=k(33:732)';
end;
fclose(inp);

//-----End Matlab Script (read_da.m)-----------------

HEX To Float......
hello guys,
Im relatively new to VB6.
I am required to convert a 4 Byte HEX value to Float value.
ie. if i have the input to be:
BE C3 F2 DF
the output should be :
- 0.382712

The 4 Byte Hex Value is in 32 Bit IEEE 754 format.
I have managed to do the above successfully in C++.
But i cant manage to get it right in VB6.
if it helps, ill post the C++ code.

lease Help me guys....
thanks.

Float CommandButtons
Hello!

I'm running into some difficulties trying to float the location of a CommandButton through VBA. I want the Command Button to float so that if scrolling to the right is done, the buttons float across the top instead of becomng obscured to the left. There is a Placement property on the CommandButton. The doc indicates that there is a xlFreeFloating property; however, it doesn't appear to be valid on the CommandButton. Freezing the panes works to a degree; however, I won't be able to use this for my solution.

Does anyone have any ideas as to whether this is possible or any other possibly solutions?

Thanks in advance!

Convert HEX To Float?
How would I convert a 4-byte HEX value into floating point?

And the inverse; how would I go about converting floating point to 4-byte HEX?

Float To Fraction
Hi,
I am looking for hint, algorithm that would help me to change a floating value to a fraction (multiplier divisor) as per example

0.005 => 1/200 easy to do as 1/0.005 = 200; so Multi = 1 and Div = 200
But
1.25 => 5/4
Any one has a clever idear or multiplying 1.25 X time until the result is an integer is my only option

Thanks

Float(single) To Hex
hi

i know vb doesn't have support for convering floats to hex,Need help on this .
so how to convert Float(single) to hex(4 bytes) and vice versa.

thanks for helping

Format Float Value
when i read a value (money value) out of database i
want to display it with 2 decimal places
ie 3.00 3.50 etc
anyone know a handy way to display the 2 decimal places
even if they are zero etc....
many thanks.............

Int - Float Dataset
Hi there

I created a database with some integers in it. Then I added the data source to the vbexpress edition, (mybasedataset was created). after that I realized that I need to change the integer fields into floats. I have changed it in mybase.mdf. When I edited table data I was able to insert some floats but created earlier dataset converts those values into integers and doesn't allow my form fields to accept floats only integers. How can I change that?

Since I'm a total beginner 80% of my work is drag and drop and editing the properties of the objects. so please try to expain it that way. - again I work on visual basic express edition 2005.

regards.

Returning Float Value In Vb
Hi all,
am working as software engineer and working with vb.i am unable to return float value from vb.how can i do that.plz help me.its top urgent..
Thanks in advance..

(Dec To Float)Help Covert From C To Vb
i need to convert this code to vb
what this code does is it takes a dec and converts it to a hex dec
for exsample

-5.625 to 0xC0B40000

i really need this
i got this from http://www.duke.edu/~twf/cps104/floating.html
i spent 2 hors working on my own funtion to make this and it was over 300's of code and at the final it turned out to always be about 1/1000 off and what im working with it cant be a fraction off or every thing goes crazy


Code:
#include <stdio.h>

int main()
{
float theFloat;
while (1) {
scanf("%f", &theFloat);
printf("0x%08X, %f
", *(int *)&theFloat, theFloat);
}
return 0;
}

Convert To Float
I was Wonder How To COnvert a 4 byte Hex Decimal to a Floating Char Any help would be aprechated. thanks in advance.

Convert Float To Hex
How to convert float to hex .
Like this 44.549999 to 33333242 (h)
i am using editbox to write a float value to a file

Can You Float A Recordset ?
Is it possible to open an instance of a recordset without it having a specific connection.

I then need to load the recordset from an array (got that bit sorted) and then use it as a source in an SQL statement to populate a table in an access database.

VB seems to hint at being able to do this but I can't find any definative syntax info.

This time I searched before I posted but the law of Sod applies.

Thanks in advance

How To 'float' Windows In MDI App?
I am not very good at programming, so can somebody please help me out with this one:
Please tell me how to 'float' specific windows in an MDI application. I do not want them to 'hide' when another window becomes active.
Thank you..

Single To Float
Does anyone know how I can packet a Single data type, say sngNum = -15.287, into four bytes (a 32-bit signed float for trnasmission)?

I've posted this a couple times and have yet to recieve a reply. Is this that hard of a question?

Thanks for your help or leads in advance.

Hex -&gt; Float (single)
I'm having this problem.

I'm requesting info from a server app and it returns info in a variety of datatypes. One of those datatypes is a float(32 bit) value. In my client app i read in the stream of packets and then break it down into sections for the different sections of info. BUT i can't seem to change the float value from the hex representation that it was sent as in the packet back to a float value on the client side

This is driving me crazy, if anyone can help i would really appreciate it

Thanks

Float And Findfirst
I have written some code to check if the value (definded as currency) selected by the user in a combo box, is present in another table, but when the value is a float (, as separator symbol) it gives the error "syntax error (comma) in expression). The variable used for the selected value is [forms]![tarieven].[combo3]
I have already tried to put that first in a variable that was defined as currency, but that didn' t help.
Does anyone know how to resolve this problem?



public Sub controle()
on error GoTo controle_error
Dim dbs as Database
Dim rst as Recordset
set dbs = CurrentDb
set rst = dbs.OpenRecordset("Tarieven", dbOpenSnapshot)
rst.FindFirst "tarief = " & [Forms]![tarieven].[Combo3] & _
" and sofinr = '" & [Forms]![tarieven].[Sofinr] & "'"

If rst.NoMatch then
MsgBox "Tarief kan niet gewijzigd of gewist worden: " & _
"Verander eerst het standaardtarief", vbOKOnly + vbSystemModal
Form.Undo
End If

controle_exit:
rst.Close
Exit Sub

controle_error:
MsgBox Err.Number & " " & Err.Description
GoTo controle_exit
End Sub




ps I already posted a message where I said that I had a problem with a combobox and currency values, but now it seems that the error wasn' t in the combobox itself

Ascii To Float
In Visual basic is there a function that will convert say "13.43" string to the double 13.43 or do I have to write my own?

Thanks

Float FAR* Convert In VB
i have create a ActiveX in VC++ and one of the Method has a parameter "float FAR* MyParameter".
When i want to use this activeX in VB, what shall i put for this paramter? From the object broswe, VB say this is a "MyParameter as single", but i still can't get it work. Any idea? TQ

Sooner Or Later, Everyone Does...

Insert A Float (SQL 7.0)
hi,

This may be a dumb question, but i have the following problem:

i have a table with 5 fields. When i do the following: insert into table1 values('String','string',99,99,'string', 'string') i get the error saying that i have to much values. This because he counts the 99,99 for two. How to fix this??

Thanx

Convert Float To String...
i'll use this code:


Code:
ActiveDocument.Tables(3).Cell((rijindex + 1), 3).Range.Text = CStr(transport)
But i'll get a Integer format

Need a float / double value:

32123,23

Is it possible to format it ? or an other function in stead of CStr ?

Converting 16 Bit Integer To 32 Bit Float
I am using a third party OCX that only supports native 16 bits. I am talking to a device through the com port that stores data as a 32 bit floating point value. I can only poll each 16 bit number one at a time, but that returns 65535 for each 16 bit register. I have been told to try using the copymemory() API call, but I am unsure on how I can get the floating point values from this. My function prototype is below:


Modbus.ReadResults(hwnd As Long,slave As Long,register As Long,RetValue As Long)

hwnd is a handler
slave is a device address
register is the physical address of the device (not computer)
RetValue is the value returned.

In order to read two successive registers, I call this .ReadResults Function twice.

Thanks for your assitance

Float User Control?
Hi All

I have a user control keypad for a touich screen app. the control is used in several different places through the app.

One place I have a small form, about the size of password gate.
Is there a way to make the keypad float from this form? that is i dot want to have to create a new form just to hold the control or make the first form large enough to hold the keypad (as will be lot of white space when keypad hidden)
like this:


not this:

Float A Picture Outside Of Form
Hi
I have couple picture boxs that can be dragged. Does anyone know how to drag them past the edge of a form and stay above the form ?

Calculating Long To Float
well there is no option
dim we as float
so i was wondering how would i convert a long to a float?

Difference Between Float And Money
wat isthe difference between float and money in sql sever?
if i am dealing with money issue and i put datatype as float is it ok?
cuz some syntax error saying that 'cant change from varchar data type to money datatype.Use CONVERT function...'.(when i label datatype as money) and when i change to float there is no problem....

Convert Integer To Float
I am trying to convert a pair of integers into a floating point variable (they should translate in a float value). I succesfully converted the pair of integers into a Long and i assumed that I was homefree by using the CDbl function. Unfortunately I am just getting the same number in the Double variable. The Long has a number like 1141187758 and this should translate in something like 530.xxx as a float. Anybody who can help me with this?

Make Toolbar Float
is there a way to make the toolbar that you create with the toolbar wizard "float"?

C To VB - Float Array To String
I need to convert my array of 8 floating point numbers into a string in my C program so i can sent it over the network so my VB program can read it.

How can i do this???

Thanks
Matt

Convert Byte To Float In VB
At my VB end i will need to convert every 4 bytes to a floating point number....how do i do this?

Matt

Copyright 2005-08 www.BigResource.com, All rights reserved