Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

IEEE 754 floating numbers from Visual Basic to PIC microcont

Status
Not open for further replies.

mabusoe

Junior Member level 3
Joined
Jun 12, 2001
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Canada
Activity points
158
ieee 754 vb6

I am trying to send a floating point number from VB to my C program runing on 16f876. In C I converted the IEE754 to a 4byte array, yet the Visual Basic does not have the same functions (UNION) is there some solution to transfer floating point number in byte format that is better?

Mabusoe
 

ieee754 vb

Does VB have pointers? I think yes. Then try to convert
this

float a;

char a1,a2,a3,a4;

a1=*(char*)&a;
a2=*((char*)&a +1);
a3=*((char*)&a +2);
a4=*((char*)&a +3);

Compiled for little endian cpu a1 will contain lowest bits of mantissa and
a4 mantissa sign+7msb of biased exponent.

kef
 

visual basic convert double ieee binary

This is what I figured out for VB:


Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Sub SingleToIEEE754()

Dim bBytes(0 To 3) As Byte
Dim rMyNumber As Single
Dim i As Integer

rMyNumber = 333.7
Call CopyMemory(bBytes(0), rMyNumber, 4)

Debug.Print Hex$(bBytes(3)); " "; Hex$(bBytes(2)); " "; Hex$(bBytes(1)); " "; Hex$(bBytes(0))
End Sub
 

vb ieee 754

This is for C:

union FloatToChar
{
double fr; // 4 bytes as a long 32 bits.
unsigned char br[4]; // 4 bytes as 4 chars
};

union FloatToChar y;


Very nifty, luckily VB and the C compiler for the microcontroller use the same format for the 32bit floating point numbers
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top