Re: Reading a binary file

Discussion in 'Python' started by Andrew Bennetts, Jun 26, 2003.

  1. On Thu, Jun 26, 2003 at 10:01:06AM +0200, Sorin Marti wrote:
    > Hi all,
    >
    > I am quite new to python and very new to this list.
    >
    > I've got following problem. I have a binary file which contains
    > information I should read. I can open the file with
    >
    > f = open ('cpu1db2.dat', 'rb')
    >
    > That's no problem. But now I need the hex values of the binary file.


    You can get the hex value of a 1-character string with hex(ord(char)), e.g.:

    >>> char = 'a'
    >>> hex(ord(char))

    '0x61'

    But I'm guessing that you might find the 'struct' module even more useful:
    http://python.org/doc/current/lib/module-struct.html

    -Andrew.
     
    Andrew Bennetts, Jun 26, 2003
    #1
    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. Neo
    Replies:
    0
    Views:
    470
  2. El Durango

    reading binary file.

    El Durango, Dec 8, 2004, in forum: Java
    Replies:
    1
    Views:
    7,559
    Gordon Beaton
    Dec 8, 2004
  3. Ron Eggler

    writing binary file (ios::binary)

    Ron Eggler, Apr 25, 2008, in forum: C++
    Replies:
    9
    Views:
    934
    James Kanze
    Apr 28, 2008
  4. Guest
    Replies:
    6
    Views:
    1,689
    Guest
    Apr 25, 2010
  5. Jim
    Replies:
    6
    Views:
    735
Loading...

Share This Page