Convert from 512 byte blocks to Megabyes and Gigabytes

It’s pretty common for me to have to make size conversions between 512 byte blocks and something more readable, such as Megabytes or Gigabytes. I’ve got a simple formula to do the conversion.

How to convert 512k byte blocks to Megabytes or Gigabytes

In simple terms the formula to convert from 512 byte blocks to megabytes is:

Number Of 512 byte blocks/2/1024

and to Gigabytes it is:

Number Of 512 byte blocks/2/1024/1024

The reason that I am making this calculation is because I often work on IBM AIX, the default output of the du command is in 512 byte blocks. I believe this is a POSIX standard.  But it is really not easy to read at a glance. Recent versions of AIX have an option on the df command to produce human readable output, but I sometimes work on ancient versions.

So for my own sake as much as anyone else’s I quickly wrote this little converter so that in future I don’t need to refer to the formula above and can just quickly get the result.

Converter for 512k byte blocks

Simply enter the output provided by the df command into the textbox below and the sizes in Megabytes and Gigabytes will be displayed.

Number of 512 byte blocks

Value in Megabytes:
Value in Gigabytes:

Hope this helps someone, I know it will help me!

If you want more information on how to do these conversions, there is a really good article on it by Brian Smith on his blog:

3 thoughts on “Convert from 512 byte blocks to Megabyes and Gigabytes

  1. Have you ever thought about creating an e-book or guest authoring on other websites? I have a blog based on the same ideas you discuss and would really like to have you share some stories/information. I know my subscribers would enjoy your work. If you are even remotely interested, feel free to send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>