VectorLinux
October 30, 2014, 07:42:36 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1] 2
  Print  
Author Topic: File size calculation question  (Read 5580 times)
M0E-lnx
Administrator
Vectorian
*****
Posts: 3187



« on: May 07, 2008, 10:24:03 am »

I've been wondering about this for a while... Maybe someone can shed some light here

In a normal shell app like xterm, doing ls -l returns list of files  with names, persmissions, and sizes

Let's talk about the sizes part
Since I started fidling with computers and stuff, I understand the different types of measuring units

Byte
KB
MB
GB
TB

And probabbly more than that
My question is, how do we calculate these things?
AFAIK, 1024B = 1MB
1024MB = 1GB

I'm trying to convert a file size from B to MB

can anyone think of a formula to do this?
Logged

exeterdad
Packager
Vectorian
****
Posts: 2046



« Reply #1 on: May 07, 2008, 10:33:45 am »

Ohhhhh maaaaaan!  I'm nowhere near the machine with all those notes on it.  I had......  Wait brb I think the machine is booted.  I'll try to ssh and look for the notes.
Logged
exeterdad
Packager
Vectorian
****
Posts: 2046



« Reply #2 on: May 07, 2008, 10:40:36 am »

It's Bytes/1048576

or Bytes divided by 1048576.
I've been working on a script to transfer mp3's and files to a mtp device.  Needed to covert bytes to MB for the nifty progress meter Smiley
« Last Edit: May 07, 2008, 10:42:53 am by exeterdad » Logged
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1552


I like the bass to go BOOM!


WWW
« Reply #3 on: May 07, 2008, 12:11:37 pm »

Actually, the amount of Bytes / kiloByte differs per ... well it differs.

Officially though:
kilo = 103
Mega = 106
Giga = 109

you can read more about it here: http://en.wikipedia.org/wiki/Kilobyte
Logged

Most music on my soundcloud page was arranged in programs running on VL.
M0E-lnx
Administrator
Vectorian
*****
Posts: 3187



« Reply #4 on: May 07, 2008, 12:21:12 pm »

So how exactly should the conversion be done?

I've got something like this

MB = Bytes / (1024 * 1024)
is this accurate enough to use?
Logged

The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1552


I like the bass to go BOOM!


WWW
« Reply #5 on: May 07, 2008, 12:42:57 pm »

That will do nicely:

1024x1024 = 1,048,576 (like exeterdad said)

It would be faster to devide through 1,048,576, that saves a multiplication (and a tiny but of memory to hold the 1024) every time that code is executed. The other possibility is to devide through 1,000,000. Both are correct and wrong, it's whichever you think is the correct one that you should use Wink.

Depending on the programming language you use you might have to typecast Bytes or 1,048,576 (or both) as (double) floats rather than (long) ints to make sure the answer isn't always rounded down to an integer. For instance, if you'd devide 1,048,575 through 1,048,576 in C without typecasting it, the answer would be 0.
Logged

Most music on my soundcloud page was arranged in programs running on VL.
Triarius Fidelis
Vecteloper
Vectorian
****
Posts: 2399


Domine, exaudi vocem meam


WWW
« Reply #6 on: May 07, 2008, 01:33:57 pm »

kilobyte - 2^10 bytes
megabyte - 2^10 kilobytes
gigabyte - 2^10 megabytes

etc. ... powers add
Logged

"Leatherface, you BITCH! Ho Chi Minh, hah hah hah!"

Formerly known as "Epic Fail Guy" and "Döden" in recent months
easuter
Global Moderator
Vectorian
*****
Posts: 2160



« Reply #7 on: May 08, 2008, 05:43:37 am »

Actually, the amount of Bytes / kiloByte differs per ... well it differs.

Officially though:
kilo = 103
Mega = 106
Giga = 109

you can read more about it here: http://en.wikipedia.org/wiki/Kilobyte


Yeah, powers of two and not powers of ten, like hanumizzle mentioned (1 byte = 8 bits, not 10).
Sneaky hard drive manufacturers love mixing the two up...   Angry
Logged

MikeCindi
Tester
Vectorian
****
Posts: 1073


« Reply #8 on: May 08, 2008, 12:12:29 pm »

Yeah, powers of two and not powers of ten, like hanumizzle mentioned (1 byte = 8 bits, not 10).
Sneaky hard drive manufacturers love mixing the two up...   Angry

Should we boycott those drive makers who are using the base 10 system for "cheating" us out of storage space?!  Wink
Logged

The plans of the diligent lead to profit...Pro. 21:5
VL64 7.1b3                                     RLU 486143
BlueMage
Vectorite
***
Posts: 274



« Reply #9 on: May 08, 2008, 03:34:48 pm »

So.... boycott all of them?
Logged

Acer Laptop:  Vector 5.8 SOHO Final & Windows XP Professional & USB (still alive!)
Compaq POS (almost dead): Vector 5.9 Light Beta 5
Quad-core BEAST: Win 7 Ultimate 64-bit & Vector 5.9 64-bit beta-2
Old 500MHz media box:  Vector 5.8 SOHO Final (dead)
701 EeePC:  Puppeee (based on Puppy 4.01)
MikeCindi
Tester
Vectorian
****
Posts: 1073


« Reply #10 on: May 08, 2008, 05:11:13 pm »

Well, perhaps it's really an issue between BIOS makers and drive makers and they're just trying to confuse me. Here's a quote from IBM:
Quote
Note: The Maximum Capacity may be smaller than the stated capacity of the drive. This is because
the BIOS of some systems recognizes a Megabyte as 1,048,576 bytes (binary). Drive manufacturers
recognize a Megabyte as 1,000,000 bytes (decimal). The capacities are the same in actual number of
bytes.

and from Seagate/Maxtor:
Quote
The storage industry standard is to display capacity in decimal. Even though in binary you have more bytes, the decimal representation of a gigabyte shows greater capacity. In order to accurately understand the true capacity of your hard drive, you have to know which base unit of measure (binary or decimal) is being used to represent capacity...
Simply put, decimal and binary translates to the same amount of storage capacity. Let's say you wanted to measure the distance from point A to point B. The distance from A to B is one kilometer or .621 miles. It is the same distance, but it is reported differently due to the measurement.
(must be new math  Tongue)

and similarly from Western Digital:
Quote
Megabyte. WD defines a megabyte as 1,000,000 (one million) bytes.

So if they "all" do it the same, using decimal, why do I feel like I've lost something when the OS uses binary. I guess I'll just have to get over it... Cry
Logged

The plans of the diligent lead to profit...Pro. 21:5
VL64 7.1b3                                     RLU 486143
rbistolfi
Packager
Vectorian
****
Posts: 2290


« Reply #11 on: May 08, 2008, 06:08:19 pm »

Well may be I am a bit plain, but I can't see how 1,048,576 can be binary. Both are decimal and same unit (number of bytes), and 1,048,576 > 1,000,000.
Logged

"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!
Triarius Fidelis
Vecteloper
Vectorian
****
Posts: 2399


Domine, exaudi vocem meam


WWW
« Reply #12 on: May 08, 2008, 06:37:57 pm »

Well may be I am a bit plain, but I can't see how 1,048,576 can be binary. Both are decimal and same unit (number of bytes), and 1,048,576 > 1,000,000.

Code:
hanumizzle:$ python
Python 2.5.1 (r251:54863, May  4 2007, 16:52:23)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.log(1048576, 2)
20.0
Logged

"Leatherface, you BITCH! Ho Chi Minh, hah hah hah!"

Formerly known as "Epic Fail Guy" and "Döden" in recent months
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1552


I like the bass to go BOOM!


WWW
« Reply #13 on: May 11, 2008, 02:32:28 am »

Quote
Should we boycott those drive makers who are using the base 10 system for "cheating" us out of storage space?! 
Actually, I think it's perfectly fine to use 1000 for a kilobyte (kilo means 1000, not 1024). It's the software manufacturers that made us believe 1024 bytes are a kilobyte because it was easier for them.
Logged

Most music on my soundcloud page was arranged in programs running on VL.
Triarius Fidelis
Vecteloper
Vectorian
****
Posts: 2399


Domine, exaudi vocem meam


WWW
« Reply #14 on: May 11, 2008, 03:33:23 pm »

Quote
Should we boycott those drive makers who are using the base 10 system for "cheating" us out of storage space?! 
Actually, I think it's perfectly fine to use 1000 for a kilobyte (kilo means 1000, not 1024). It's the software manufacturers that made us believe 1024 bytes are a kilobyte because it was easier for them.

The software convention of 1024 bytes per KB is correct, because it is more natural. Decimal-based computers basically ceased to be in the late 1940's. As such, the sizes of hard drives and memory units are best measured in units of 2n.
Logged

"Leatherface, you BITCH! Ho Chi Minh, hah hah hah!"

Formerly known as "Epic Fail Guy" and "Döden" in recent months
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!