Bit Manipulation, Binary Files, Math

N

nguser3552

Hello Everyone,

I have a problem I can't surmount, anything is gravy at this point.
I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary
format. I can do this in C, but have to use:
int main(int argc,char** argv)
which is archaic.
My compiler is Visual Studio 5.0 Pro.

To make my dilemma as clear as possible:
1. I need to accomplish the above (open any file format in binary)
2. Place the data in an array.
3. Produce one, all be it, large one line integer with no spaces (Bit
Manipulation I would guess) from the array - output #4 explains why.
4. Finally be able to perform mathematics on the "lengthy" integer using
(trig, calculus).

Hoping not to anger anybody - the goal is to be able to get any type of file
to base2 without interval spaces and then have the ability to use an
equation on that particular files' base2 equivalent.

Any and all help is naturally greatly appreciated, because my back is up
against the wall and I'm a bit out of my league with how to carry this out
in C++ effectively.

Thank you for your time.
 
J

Jack Klein

Hello Everyone,

I have a problem I can't surmount, anything is gravy at this point.
I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary
format. I can do this in C, but have to use:
int main(int argc,char** argv)
which is archaic.

No it is not "archaic", it is perfectly valid C today and has been for
nearly 20 years. It is also exactly the way that all standard C
programs start today, if they want to use command line arguments.

So what is your problem with a C or C++ program that starts that way?
My compiler is Visual Studio 5.0 Pro.

That is a very old version of Visual Studio, it
To make my dilemma as clear as possible:
1. I need to accomplish the above (open any file format in binary)

You can use fopen("filename", "rb") in a C or C++ program. Or you can
use a C++ iostream with the binary flag. What is your particular
problem with opening a file in binary mode for reading?
2. Place the data in an array.

Reading a binary file byte-by-byte and storing in an array is quite
simple. An array of unsigned char is the best choice for the
destination. What is your particular problem with reading bytes from
a binary file into an array?
3. Produce one, all be it, large one line integer with no spaces (Bit

I have no idea what you mean by a "large one line integer with no
spaces". You will have to explain more. What kind of integer, one of
the standard types like int or unsigned long? How "large", and what
does "one line" mean?
Manipulation I would guess) from the array - output #4 explains why.

Why do you think bit manipulation is necessary? If you start with a
binary file of, for example, 1000 bytes, and read it into an array of
1000 unsigned characters, you can consider it 1000 byte integer, if
you want to.
4. Finally be able to perform mathematics on the "lengthy" integer using
(trig, calculus).

I don't understand this at all.
Hoping not to anger anybody - the goal is to be able to get any type of file
to base2 without interval spaces and then have the ability to use an
equation on that particular files' base2 equivalent.

Yes, that's simple. Open the file in binary mode using either the C
FILE * functions or the C++ iostream functions. Read it byte-by-byte
into a large enough array of unsigned chars. I have no idea what you
mean by "interval spaces", but if you read a binary file byte-by-byte
into an array of unsigned chars, there won't be anything in the array
that wasn't in the file.
Any and all help is naturally greatly appreciated, because my back is up
against the wall and I'm a bit out of my league with how to carry this out
in C++ effectively.

Thank you for your time.

I think you should post again and provide a better description of the
problem you are trying to solve. You seem to think that you need to
perform trigonometry on some non-angular value that you somehow
compute from the raw bytes of a binary file.

Explain the real requirement that you are trying to meet, and perhaps
people can suggest a reasonable method of accomplishing it. There
exist all sorts of existing code for computing a hash or checksum or
other relatively unique numeric value from the contents of a file, if
that's what you are trying to do.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
R

red floyd

nguser3552 said:
Hello Everyone,

I have a problem I can't surmount, anything is gravy at this point.
I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary
format. I can do this in C, but have to use:
int main(int argc,char** argv)
which is archaic.

That's not archaic. ISO/IEC 14882:2003 specs int main(), and int
main(int argc, char *argv[]);

My compiler is Visual Studio 5.0 Pro.
This, on the other hand, is definitely archaic. VS5 (aka VS97) predates
the standard by at least 2 VC versions. You need to upgrade to VC7.1 at
the least.


as for the rest, I'm not quite sure what you were getting at.
 
A

ajk

1. I need to accomplish the above (open any file format in binary)
2. Place the data in an array.
3. Produce one, all be it, large one line integer with no spaces (Bit
Manipulation I would guess) from the array - output #4 explains why.
4. Finally be able to perform mathematics on the "lengthy" integer using
(trig, calculus).

Hoping not to anger anybody - the goal is to be able to get any type of file
to base2 without interval spaces and then have the ability to use an
equation on that particular files' base2 equivalent.

you would trouble finding a "lengthy integer with no spaces"

you can treat any file as a binary file by opening it in binary mode
using fopen("somename","rb").

once you have done that, you can load the bytes from the file into an
array of bytes or other data type.

so basically any data type would do as buffer:

long buffer[1024];

/* now read 1024 * 4 bytes */
fread( (void*)buffer, sizeof( buffer ), 1, fp )

or

unsigned char buffer[4192]

/* now read 4192 bytes */
fread( buffer, sizeof(buffer), 1, fp )


hth
/ajk
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top