PDA

View Full Version : Quick Tip: Bytes to kb -mb -gb


SUF6NEWBIE
08-28-2004, 05:53 PM
..may prove usefull (maybe a built in action in next Update release - hint)

How to do exact conversion of BYTES to megabytes and so on...

Calc_const = "1024"; --correct math constant for Windows file systems
--or just replace any entry using variable: Calc_const with: 1024

eG Code:

filesize = "100000000" --bytes (used just to test)

--now convert to Kilobytes
filesize_kb = (filesize / Calc_const ); --show all decimal returns
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Kilobytes: "..filesize_kb);
--now convert to Kilobytes --return to 1 decimal place only
filesize_kb = Math.Round((filesize / Calc_const ), 1 ); --to one decimal place
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Kilobytes: "..filesize_kb);

--convert to Megabytes
filesize_mb = Math.Round((filesize_kb / Calc_const ), 1 );
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Megabytes: "..filesize_mb);
-- OR:
filesize_mb = Math.Round(((filesize / Calc_const) / Calc_const) , 1 );
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Megabytes: "..filesize_mb);
-- OR:
filesize_mb = Math.Round((filesize / 1048000), 1 ); --quick (not exact)
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Megabytes(quick): "..filesize_mb);

--convert to Gigabytes
filesize_gb = Math.Round((filesize_mb / Calc_const ), 1 ); -- gigabytes
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Gibabytes: "..filesize_gb);
--OR:
filesize_gb = Math.Round((((filesize / Calc_const) / Calc_const) / Calc_const) , 1 );
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Gibabytes: "..filesize_gb);
--OR:
filesize_gb = Math.Round(((filesize / 1048000) / Calc_const ), 1 ); -- quick
Dialog.Message("Test Convert: "..filesize.." bytes" , "to Gibabytes(quick): "..filesize_gb);

--check using system calculator or a 'real one'
--check a file on the System and compare results
--if sample code proves to be incorrect feel free to hang me by the toes !!

eric_darling
08-29-2004, 12:55 PM
Hey, cool script! I was thinking of doing something along those lines myself whenever I scared up some free time, which is becoming increasingly difficult. Thanks for that code - that should make it a lot easier.

SUF6NEWBIE
08-30-2004, 02:24 PM
Ta ERIC,

Couple more file size "limits". --bytes

Fat16 max filesize limitation: 2147483648 (less than)
Fat32 max filesize limitation: 4294967296 (less than)
NTFS essentially No limitation


Storage Media "safe size" limits:

74 min Cd-Rom (650mb) = 681574400
80 (703mb) = 737148928
120 Dvd-R (4464mb)= 4680843264

..std dvdrom media stating "4.7 gig" is misleading
as the lead in and lead out space required gobbles
some of this..so the 'common consensus' out there
is make max write space limit the 4464 megabytes for Std Dvd Media

Anyone who wishes to add to this list or 'clarify' ..please do so...
for example some 'fully tested" ZIP DRIVE safe storage space limits

BTW for 'maximum compatibility' for data access on 'old' cdrom drives
if burning to 703mb media --keeping the burnt space to under 650meg
on this media type will often enable old drive-old firmware to read the
data correctly...

Intrigued
08-30-2004, 02:38 PM
Just wanted to stop in and say thanks!

I put these code snippets in my Code Keeper software!

Thanks again!

Very Sincerely,

eric_darling
08-30-2004, 02:50 PM
..std dvdrom media stating "4.7 gig" is misleading
as the lead in and lead out space required gobbles
some of this..so the 'common consensus' out there
is make max write space limit the 4464 megabytes for Std Dvd Media


Well, "4.7" refers to binary Gigabytes, which is accurate. If you are using what everyone (including drive manufacturers) refer to as a "Gigabyte," DVD-R media is 4.37 approx. So, as long as you know what flavor of GB people are talking about, you're all set.

I've built a Windows app using AMS that will do conversions for file sizes. It's especially helpful for those of us who produce video and audio files commonly bound for optical media and the web. Basically, it's pretty hard to do a bits - megabytes conversion on the fly in your head unless you're a math savant. So, I've always had to go to the web to use PHP scripts that run these calculations for me. I got tired of that, especially when one of those sites I use went down. So, I built my own - accuracy is verified: It's called
Bitrate Calc 1.0 (http://www.videoconstruction.com/bitratecalc), and available for download at that link.

SUF6NEWBIE
08-30-2004, 02:58 PM
no problemo Intrigued..

tks for reminding me about BRETT's codekeeper..must start taking
advantage of it...hope the "shop" is do'in well for you...

SUF6NEWBIE
08-30-2004, 03:03 PM
Tks for the headsup Eric...downloaded your Bitratecalc...many thanks
for sharing your code - time All the best with your BIZ..also

Martin

eric_darling
08-30-2004, 03:10 PM
Actually, that's just the executable - if anyone wants the source code, just snap me an e-mail. And more than welcome, Martin - always glad to be able to give back whenever it's possible. This community has been very helpful and actually has truly saved my keester a couple of times!

Intrigued
08-30-2004, 03:54 PM
no problemo Intrigued..

tks for reminding me about BRETT's codekeeper..must start taking
advantage of it...hope the "shop" is do'in well for you...
The 'shops' going good, thanks.

eric, that's a cool little application. My wife does not like that I send (but receive is ok, go figure) Paypal payments. If you have a PO BOX... I would be happy to slap a $5'er in the mail for the support of the Bitrate Calc software.

That's pretty dang cool little application! :yes

Intrigued

eric_darling
08-30-2004, 06:22 PM
Thanks for the kind words - I appreciate it!

Intrigued
08-30-2004, 06:23 PM
Anytime Eric!

Thanks again,

Intrigued

Brett
08-31-2004, 09:45 AM
Eric,

Just wanted to say congrats on releasing a piece of software. It is cool to see someone like you (non-programmer by trade) create industry-specific software using AMS50. This is exactly the kind of thing that we hoped to see when creating the product. Keep up the good work!

eric_darling
08-31-2004, 02:07 PM
Eric,

Just wanted to say congrats on releasing a piece of software. It is cool to see someone like you (non-programmer by trade) create industry-specific software using AMS50. This is exactly the kind of thing that we hoped to see when creating the product. Keep up the good work!
Thanks, Brett! Yeah - it's something I've been meaning to do more of, but it's been kinda crazy around here what with business and all. This one just made sense because I got fed up with doing calculations by hand, and I figured other folks like me were out there.

It's a very simple program, and kind of a no-brainer project. I'm sure it could even be coded more efficiently. But it works, and it's accurate. It was so easy - 30 minutes in AMS - I spent more time putting together the HTML to describe what the software does. I still can't believe how easy it is to program using AMS 5. And I love the ease with which I can expand into new functionality.