read a Unix binary file

A

Arnaud Boëlle

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
 
S

sali

Arnaud Boëlle said:
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
 
A

Arnaud

sali said:
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,
 
S

sali

Arnaud said:
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/packages/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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top