+ Reply to Thread
Results 1 to 4 of 4

read a Unix binary file

  1. #1
    Arnaud Boëlle
    Guest

    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



  2. #2
    sali
    Guest

    Re: read a Unix binary file

    "Arnaud Boëlle" <boelle.arnaud@neuf.fr> wrote in message
    news:d3tu60$dop$1@aphrodite.grec.isp.9tel.net...
    > 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






  3. #3
    Arnaud
    Guest

    Re: read a Unix binary file


    "sali" <gabor.salai@tel.net.ba> a écrit dans le message de news:
    exMJWI7QFHA.3188@TK2MSFTNGP10.phx.gbl...
    > "Arnaud Boëlle" <boelle.arnaud@neuf.fr> wrote in message
    > news:d3tu60$dop$1@aphrodite.grec.isp.9tel.net...
    >> 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,




  4. #4
    sali
    Guest

    Re: read a Unix binary file

    "Arnaud" <boelle.arnaud@neuf.fr> wrote in message
    news:d41a03$t8a$1@aphrodite.grec.isp.9tel.net...
    >
    > "sali" <gabor.salai@tel.net.ba> a écrit dans le message de news:
    > exMJWI7QFHA.3188@TK2MSFTNGP10.phx.gbl...
    > > "Arnaud Boëlle" <boelle.arnaud@neuf.fr> wrote in message
    > > news:d3tu60$dop$1@aphrodite.grec.isp.9tel.net...
    > >> 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1