Read Binarys Problem and Linux

Discussion in 'Perl Misc' started by Tex, Jun 15, 2005.

  1. Tex

    Tex Guest

    I have a program that reads a binary data file in Unix and works just
    fine, however when I tried it in Linux the read and unpack commands did
    not give me the same answer. I am trying to simply read a short
    integer. In Unix, the $nscan is around 20000, in linux it is a huge
    number or even negative. I belive that the problem has to do with
    bigendian vs littleendian, but when I try different combinations of
    unpack options nothing works.
    Thanks
    tex

    open(F, "$filein") or die "Unable to open file";
    binmode(F);
    read(F,$packscans, 4);
    $nscan = unpack("i*",$packscans);
     
    Tex, Jun 15, 2005
    #1
    1. Advertising

  2. Tex wrote:
    > I have a program that reads a binary data file in Unix and works just
    > fine, however when I tried it in Linux the read and unpack commands did
    > not give me the same answer. I am trying to simply read a short
    > integer. In Unix, the $nscan is around 20000, in linux it is a huge
    > number or even negative. I belive that the problem has to do with
    > bigendian vs littleendian, but when I try different combinations of
    > unpack options nothing works.
    > Thanks
    > tex
    >
    > open(F, "$filein") or die "Unable to open file";
    > binmode(F);
    > read(F,$packscans, 4);
    > $nscan = unpack("i*",$packscans);


    Can you post the output of 'dd if=<file> bs=4 count=1 | OD -TXc'?
    WRT endianness: what is the processor of the Unix box and what is Linux
    running on?

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Jun 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. U. George
    Replies:
    4
    Views:
    869
    U. George
    Aug 11, 2005
  2. keithb
    Replies:
    2
    Views:
    8,051
    keithb
    Jun 7, 2006
  3. Replies:
    1
    Views:
    1,049
    Pascal J. Bourguignon
    Apr 22, 2008
  4. Ben Aroia

    native binarys

    Ben Aroia, Feb 28, 2008, in forum: Ruby
    Replies:
    1
    Views:
    83
    Arlen Cuss
    Feb 28, 2008
  5. Krishna Chaitanya
    Replies:
    1
    Views:
    148
    Krishna Chaitanya
    Feb 27, 2009
Loading...

Share This Page