UnitOfMemory – Measure and convert you bytes

Not very often do I need to take a number of bytes and convert them into the most appropriate measurement.  This came up recently on a project and I thought it would be nice to just create a class to handle this for me.  So I created UnitOfMemory as enum that switches between Byte, KiloByte, MegaByte, GigaByte, TeraByte, and PetraByte.  This works very nicely to be able to select the appropriate unit to measure with the number of bytes I have, and then to convert.

This is just a simple Java Enum that uses a enum constructor to create an enum type based on the unit of measure of memory.

 

 

Leave a Reply

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