Solved

Reading Binary data

Posted on 2006-06-23
2
242 Views
Last Modified: 2010-04-01
I have a file of binary 1s and 0s that I want to read in chunks of size 64, for example read the 1st 64 bits into an integer array of size 64, proccess it and then read the next 64 and so on until the end of file.
How would I do this, I couldn't find a function that reads integer data from file, I tried using the function get() and cast the returned value but it gave me an array of 48s and 49s which are the ASCIIs of 1s and 0s.

Thanks in advance.
0
Comment
Question by:JessyEzzy
2 Comments
 
LVL 9

Expert Comment

by:DrAske
Comment Utility
here is an idea ..

when you read the data using *getline* function ..then add if statement inside the for loop ..
for(int i =0; i<size; i++){
if(array[i] == '1')
   // process it
else
 // when it is not '1' do whatever you want ..
}
0
 
LVL 16

Accepted Solution

by:
imladris earned 80 total points
Comment Utility
Since you are getting 48's and 49's it would appear that you have a file full of ASCII ones and zeroes. If my guess is correct then the file can be opened up with notepad, and you will see a bunch of 1's and 0's.

If so, then the file is actually a text file. One simple way to get this into an integer array might be to read each character, and then convert it to an integer in the next array element. Something like:

char bc;
int barray[64];
for(int i=0; i<64; ++i)
{   bc<<cin;
    barray[i]=(bc-'0');
}

Each text one or zero is read into a character. It is then converted to an integer by subtracting the character '0' (decimal 48) from it.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now