Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to write less than 1 byte to a file

As far as I know the smallest unit in C is a byte. Where does this constraint comes from? CPU?

For example, how can I write a nibble or a single bit to a file?

like image 702
cyraxjoe Avatar asked Jul 14 '11 23:07

cyraxjoe


People also ask

Why is a character 1 byte?

the (binary) representation of a char (in standard character set) can fit into 1 byte. At the time of the primary development of C , the most commonly available standards were ASCII and EBCDIC which needed 7 and 8 bit encoding, respectively. So, 1 byte was sufficient to represent the whole character set.

What is the size of an empty file?

If the file has no content, it has a size of zero. The file name is as much a part of the file as your own name is physically a part of you (ie, it isn't).

How many characters make a byte?

Eight bits are called a byte. One byte character sets can contain 256 characters.

Can a file ever have a length of 0 bytes?

A zero-byte file is a file that does not contain any data. While most files contain several bytes, kilobytes (thousands of bytes) or megabytes (millions of bytes) of information, the aptly-named zero-byte file contains zero bytes. Usually a file will contain at least a few bytes.


1 Answers

no, you can't... files are organized in bytes, it's the smallest piece of data you can save.

And, actually, that 1 byte will occupy more than 1 byte of space, in general. Depending on the OS, the system file type, etc, everything you save as a file will use at least one block. And the block's size varies according to the file system you're using. Then, this 1-bit will be written as 1 - byte and can occupy as much as 4kB of your disk.

In wikipedia you can read something about the byte being the smallest data unit in many computers.

like image 97
woliveirajr Avatar answered Oct 22 '22 03:10

woliveirajr