Thread: Reading Binary Data

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Unhappy Reading Binary Data

    hey, I am having problems reading binnary data. When I try to read the hex value "1a" into a string, it messes up since "1a" is a messed up character on the ascii chart. Does anyone know how I can read this into an integer?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Post a snippet of code, showing what you're trying to do, and someone will help you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Say I have a binary file that looks like this:
    19 00 00 00 01 1a 00 00 00 01 1b 00 00 00 01

    I can read the file like this:

    Code:
    char buffer[5];
    for(int i = 0; i < 3; i++)
    {
        file.read(buffer, 5)
        cout << buffer << "\n";
    }
    It reads the first 5 bytes but when it reaches the 1A it gets messed up. If i Change the 1A to anything else it will wok. I think the reason for this is becuase 1A is the ascii value for substitute which messes it up. So how can I read this file into integer's instead of char's?

    So It would look something like this(which doesn't work)
    Code:
    int buffer[5];
    for(int i = 0; i < 3; i++)
    {
        file >> buffer;
        cout << buffer << "\n";
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Reading and writing binary data
    By Yasir_Malik in forum C Programming
    Replies: 3
    Last Post: 12-12-2004, 09:24 AM
  2. Reading a line of data...
    By RedZippo in forum C++ Programming
    Replies: 10
    Last Post: 04-04-2004, 02:14 AM
  3. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  4. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 02:24 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM