LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default faster way to convert hex to ieee754?

I am converting Hex to ieee754 floating point numbers using the following
attached code using VBA. Is this a 'fast' way to do this operation? My code
spends 90% of the time performing this operation. I'm hoping there is a
faster way. Any comments are apprectiate.

Thanks!
Mark


'To type cast in VB you need to use the API to copy the contents of one data
type into another....
'turns hex data into floating point ieee754 standard
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Function Hex2Ieee754(b1, b2, b3, b4)

Dim bytArray(0 To 3) As Byte
Dim fResult As Single

' load your data (40 B8 00 00) into a byte array creates 5.75
' note the order is reversed

bytArray(3) = "&H" + b1
bytArray(2) = "&H" + b2
bytArray(1) = "&H" + b3
bytArray(0) = "&H" + b4

' copy into the float
CopyMemory fResult, bytArray(0), 4
' print the result (5.75)
'Debug.Print fResult
Hex2Ieee754 = fResult

End Function

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ieee754 single precision numbers staff Excel Discussion (Misc queries) 2 May 31st 07 03:07 PM
Faster way to do this? Ed Excel Programming 1 November 14th 05 04:27 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
Is there a faster way Jim May Excel Programming 3 September 19th 04 04:42 AM
Which one is faster? Syed Zeeshan Haider[_4_] Excel Programming 14 December 4th 03 05:28 PM


All times are GMT +1. The time now is 01:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"