473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Binary files

hi all,
Can anybody please tell the advantages which the binary files offers
over the character files.

Thanks,
Alice walls

Nov 14 '05 #1
6 2230

"alice" <al***********@yahoo.com> a écrit dans le message de
news:11**********************@c13g2000cwb.googlegr oups.com...
hi all,
Can anybody please tell the advantages which the binary files offers
over the character files.

Thanks,
Alice walls


Direct data access I think mainly.

K
Nov 14 '05 #2
alice wrote:
hi all,
Can anybody please tell the advantages which the binary files offers
over the character files.

What do you think? Do you know what the differences are? Why do you
want to know? What problem are you trying to solve.

Various file types are correct for various problem sets. There is no
blanket answer.


Brian
Nov 14 '05 #3
alice wrote:
hi all,
Can anybody please tell the advantages which the binary files offers
over the character files.


Sounds a little bit like a homework assignment.

I'll take the risk:
Let us assume we have a platform/implementation with bytes of
8 bits and 32 bit ints and 64 bit doubles which can be considered
IEEE doubles.
Now, if you store a very small negative integer number, say
-1000000000, you need (up to) 11 bytes whereas storing it in
binary takes only 32/8=4 bytes; similarly for doubles:
Storing a number as text (decimal fraction) takes up to 23
bytes whereas the binary takes only 8 bytes.
So, you save some (disk) space.

On the other hand, the binary representation on another
platform may be different which means that you can no longer
use the old files. Storing everything as text means that
you only have to use a standard tool for text file conversion
and can further use your old data files.
Another point: If everything is written out as text, you are
able to manually tweak the data if needed, only using a simple
text editor. Tweaking binary files usually is not much fun...

Have also a look at the comp.lang.c FAQ. It is probably best
if you download the text version and just search for "binary":
ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.gz
For the HTML version start from here:
http://www.eskimo.com/~scs/C-faq/top.html
Note that this answer is not "complete"; there are of course
platform-independent "binary" files but there you do not store
objects from the memory directly to the file but convert them
to a certain format beforehand.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #4
"KiLVaiDeN" wrote...

Direct data access I think mainly.

K


By that I mean that with binary files, you can do some "structures" like
chained list or b-trees quite easily, while with character files it's pretty
hard.
Binary files are much more flexible, and since each "row of data" is
supposed to have the same size, you can access very fast to any data in the
file by moving from the "date size" in bytes, which is impossible in
character files.
Also as it was alrdy said, in binary files you can store real
representations of datas like ints, doubles, or any other data ( it's called
"serializing data" by the way ) which is once again impossible to do in a
character file, which is only a "string" representation of data.

K
Nov 14 '05 #5
KiLVaiDeN wrote:
"KiLVaiDeN" wrote...
Direct data access I think mainly.

K

By that I mean that with binary files, you can do some "structures" like
chained list or b-trees quite easily, while with character files it's pretty
hard.


Agreed, as a generality.
Binary files are much more flexible, and since each "row of data" is
supposed to have the same size, you can access very fast to any data in the
file by moving from the "date size" in bytes, which is impossible in
character files.
You lost me there: binary files are more flexible because
they're more rigid? You're confusing the unrelated concepts
of structure and encoding.
Also as it was alrdy said, in binary files you can store real
representations of datas like ints, doubles, or any other data ( it's called
"serializing data" by the way ) which is once again impossible to do in a
character file, which is only a "string" representation of data.


Nonsense. As a trivial counter-example, consider UUencoded
data streams: entirely textual (and from a limited character
set at that), yet capable of representing any arbitrary bit
pattern.

--
Er*********@sun.com

Nov 14 '05 #6
> > Binary files are much more flexible, and since each "row of data"
is
supposed to have the same size, you can access very fast to any data in the file by moving from the "date size" in bytes, which is impossible in character files.


You lost me there: binary files are more flexible because
they're more rigid? You're confusing the unrelated concepts
of structure and encoding.


Easier to parse. If you have a bitmap where each row of pixels will
take up 256 bytes, you just have to add 256 to your current position to
move down a pixel. If we tried writing a bmp as a text file like below
(and I mean saved as ascii):

0 0 0 0 0 0 0 0 0 0
256 256 256 256 256 256 256 256 256 256
0 0 0 0 0 0 0 0 0 0
256 256 256 256 256 256 256 256 256 256

Then you're going to have to count the number of space ' ' characters
and end of line characters '\n' (maybe "\r\n") to find the next pixel
row and desired pixel. Then you will need to convert the ascii
characters '0' or '2''5''6' into a binary representation that your
computer understands. It will be a little bit easier if you save your
text file as:

000 000 000 000 000 000 000 000 000 000
256 256 256 256 256 256 256 256 256 256
000 000 000 000 000 000 000 000 000 000
256 256 256 256 256 256 256 256 256 256

as at least then you can use simple math to calculate the position of
the start of each ascii representation of the values.
Also as it was alrdy said, in binary files you can store real
representations of datas like ints, doubles, or any other data ( it's called "serializing data" by the way ) which is once again impossible to do in a character file, which is only a "string" representation of data.


Nonsense. As a trivial counter-example, consider UUencoded
data streams: entirely textual (and from a limited character
set at that), yet capable of representing any arbitrary bit
pattern.


You can represent any pattern using only hieroglyphs, that doesn't mean
that your program can just suck it in and go without extraneous
overhead.

For instance, one can do things like:

struct pixelData {
unsigned char r;
unsigned char g;
unsigned char b;
} myData[10][4];

read(fhandle, (char*)myData, sizeof(myData));

And have all of your data filled into your multidimensional array and
ready without a single ounce of conversion.
(Note that this may not be safe dependent on the source and kind of
data.)
UUEncode will first require that the text data is unencoded.

-Chris

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
28
by: wwj | last post by:
void main() { char* p="Hello"; printf("%s",p); *p='w'; printf("%s",p); }
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
8
by: dagecko | last post by:
Hi I would like to know how to detect if a file is binary or not. It's important for me but I don't know where to start. Ty
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
15
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
3
by: masood.iqbal | last post by:
Hi, Kindly excuse my novice question. In all the literature on ifstream that I have seen, nowhere have I read what happens if you try to read a binary file using the ">>" operator. I ran into...
9
by: deepakvsoni | last post by:
are binary files portable?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.