File's size as bits?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

File's size as bits?

Post by MasterGod »

When I see that a file has 1k size does it mean it has 1024*8 bits ?
So if I could see the file as 01010101 I would have seen 8192 bits?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, if you mean that you see this isze by IReadFile->getSize(). If you see it in the Explorer view of windows it might be a total different number (because usually the occupied disk space is shown). But for direct file access you see the byte count.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Why would you want to measure file size in bits? As hybrid kinda pointed out, IReadFile::getSize() returns the number of bytes.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: File's size as bits?

Post by greenya »

MasterGod wrote:When I see that a file has 1k size does it mean it has 1024*8 bits ?
So if I could see the file as 01010101 I would have seen 8192 bits?
On both questions the answer is "Yes".

The size of any file will always lie on the 8-bit-edge. It means that file can't be 15 or 201 bits long. It can be 0, 8, 16,... 256... bits long. So you never need to know how much bits does file consists of. Quantity of bits will always be filesize()*8.

Another thing that file on the physical disk takes a little bit more space. For example in some cases on FAT file systems any file on disk will occupy the space that will be dividable on 4KB (4096 bytes) -- it means that if file will be 1 byte long it will occupy 4096 bytes, if it will be 4097 bytes long -- it will occupy 8192 bytes and so on. This is also means that you cannot create infinite number of empty files on the disk.

For real example: very long time ago i was testing a diskette (1.44mb formated with FAT16 file system. The size of cluster was 1 or 2 Kb -- don't remember exactly ). Any way -- you may try to create as much as possible empty files (just in the root of the diskette) -- you will see that it will be less than 200 (two hundred(!)) ......... i am not sure in exact values, but i hope you got me :).
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Thanks.

And vitek, I just want to learn how computers work. (yeah yeah I know its not even the beginning of the beginning of the beginning)
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
L1zb3th
Posts: 15
Joined: Thu Jul 26, 2007 1:27 am

Post by L1zb3th »

simple, using a FILE* pointer, using fseek to SEEK_END and getting the size with ftells, and theeeeen, the number in bytes, pas them to bits xD
this only works with files that aren't on a zip ...
Au Revoir !
My Gramathicalz horrorz are precalkulated, zo Zhut Up !
_______
Bah, actually my english is poor, but...
forget it xDDDD
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you use the getSize() from Irrlicht it also works for zip files and other supported file systems. And for normal files it's just using ftell.
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

A byte can have a total value of 255 unsigned and 128 signed is that correct? including the 0. Where a Signed Value is either a - or + and Unsigned is +-.

Its based on the 2 to the power system so with 8 positions reading from right to left the values would be.

Code: Select all

128(2^7), 64(2^6), 32(2^5), 16(2^4), 8(2^3), 4(2^2), 2(2^1), 1(2^0),

The use of binary can also be seen in color depths such as 16, 32 bit.

All digital processors are based of the stream of 0 or 1. 0 Being of and 1 being on. Or in boolean terms 0 being false and 1 being true.


[/code]
Programming Blog: http://www.uberwolf.com
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

So why INT's range (using 2 bytes) is 32767?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

There are short and long ints, irrlicht types like f32, u16 s32 etc... are useful because they remove the doubt.

(how does a compiler decide if a generic "int" is a short or a long? I dont know)
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

int is neither long nor short, it's simply an int. There is also the type short, as well as long (and as an extension also long long - note that according to gcc long long long is too long :wink: ). There are no defined bit sizes for any of these types, the longer types just have to be at least the size of the smaller one, so char <= short <= int <= long <= long long. On 32bit machines, int is usually 32bit wide. However, on 64bit machines they are also 32bit wide. But there are also some systems which have smaller ints.
Post Reply