Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read a Unix binary file

Hi,

I need to read unix binary files with Excel VBA.

The problem is not to read a binary file. I use :

Dim buffer(1 to 1000) as single
Open file For Binary As 1
Get #1, 1, buffer

The problem is that IEEE binary information are stored left-to-right in UNIX
and right-to-left in WINDOWS
(or the contrary).

I found a first solution to this problem which is

read binary data in a buffer of byte
invert 4 by 4 the bytes of buffer
write buffer in a new binary file
read binary data

Does anyone know a better solution ?

thanks,

Arnaud


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default read a Unix binary file

"Arnaud" wrote in message
...

"sali" a écrit dans le message de news:
...
"Arnaud Boëlle" wrote in message
...
Hi,

I need to read unix binary files with Excel VBA.

The problem is not to read a binary file. I use :

Dim buffer(1 to 1000) as single
Open file For Binary As 1
Get #1, 1, buffer

The problem is that IEEE binary information are stored left-to-right in

UNIX
and right-to-left in WINDOWS
(or the contrary).

I found a first solution to this problem which is

read binary data in a buffer of byte
invert 4 by 4 the bytes of buffer
write buffer in a new binary file
read binary data

Does anyone know a better solution ?


i usualy do a in_memory_swap.

if i need to read long_int, read for bytes from file,
than, in reverse order create character (hex) representation
and let clng() function make number, or
simply multiplying read bytes like:
byte1*256^3+byte2*256^2+byte3*256+byte4



I understand the second solution you propose :
byte1*256^3+byte2*256^2+byte3*256+byte4.
How to do the same for Single ?

I don't understand the first one. How to make a character (hex)
representation ?
I've tried :

dim buffer (1 to 4) as byte
dim x as single
get #1,,buffer
x=csng(buffer) <-------- refused by the compiler !

Thank you for your help,


for i=1 to 4
hx$(i)=hex$(byte_array(i))
next
mylng=clng("&H" & hx$(2) & hx$(1) & hx$(4) & hx$(3)) 'just as example of
permutation/reconstruction

floating point number is more complicated than integer.
here is "ieee" reperesentation of 32-bit single float, bit-by-bit.
-------------
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1 8 9 31

The value V represented by the word may be determined as follows:


V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent the
binary number created by prefixing F with an implicit leading 1 and a binary
point.
-------------------
original text from:
http://www.psc.edu/general/software/...ieee/ieee.html
[my altavista found near 1million pages dealing with ieee format, this is
just from first of them]

knowing that structure you may recalculate original value, piece-by-piece.
although, i am not sure does hi-lo byte/word swapping apply to float number,
or just integers.



Reply
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
How to do a UNIX-style diff between two versions of an Excel file Kilongen Excel Discussion (Misc queries) 3 August 10th 09 05:31 PM
read excel with a c++ program on Unix [email protected] Excel Worksheet Functions 1 July 27th 06 10:10 PM
How can I read/write file with binary format??? NC Excel Programming 2 May 27th 04 09:35 AM
Unix Directory/File Listing enchilada Excel Programming 0 December 10th 03 07:46 AM
file transfer to/from a unix machine rajib Excel Programming 0 September 18th 03 03:54 PM


All times are GMT +1. The time now is 07:54 AM.

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

About Us

"It's about Microsoft Excel"