Class Conversion

java.lang.Object
org.cloudbus.cloudsim.util.Conversion

public final class Conversion
extends Object
Utility class that provides a set of methods for unit conversion.
Author:
Manoel Campos da Silva Filho
See Also:
TimeUtil, MathUtil
  • Field Summary

    Fields
    Modifier and Type Field Description
    static double GIGA
    The value of 1 GigaByte in Bytes or 1 Giga-bit in bits.
    static double HUNDRED_PERCENT
    A value that represents 100% in a scale from 0 to 1.
    static double KILO
    The value of 1 KiloByte in Bytes or 1 Kilo-bit in bits.
    static double MEGA
    The value of 1 MegaByte in Bytes or 1 Mega-bit in bits.
    static int MILLION
    One million in absolute value, usually used to convert to and from Number of Instructions (I) and Million Instructions (MI) units.
    static double TERA
    The value of 1 TeraByte in Bytes or 1 Tera-bit in bits.
  • Method Summary

    Modifier and Type Method Description
    static double bitesToBytes​(double bits)
    Converts any value in bits to bytes, doesn't matter if the unit is Kilobits (Kb), Megabits (Mb), Gigabits (Gb), etc.
    static int boolToInt​(boolean bool)
    Converts a boolean value to int
    static double bytesToBits​(double bytes)
    Converts any value in bytes to bits, doesn't matter if the unit is Kilobytes (KB), Megabytes (MB), Gigabytes (GB), etc.
    static double bytesToGigaBytes​(double bytes)
    Converts a value in bytes to GigaBytes (GB)
    static double bytesToKiloBytes​(double bytes)
    Converts a value in bytes to KiloBytes (KB)
    static double bytesToMegaBits​(double bytes)
    Converts a value in bytes to Megabits (Mb)
    static double bytesToMegaBytes​(double bytes)
    Converts a value in bytes to MegaBytes (MB)
    static String bytesToStr​(double bytes)
    Converts a value in bytes to the most suitable unit, such as Kilobytes (KB), MegaBytes (MB) or Gigabytes (GB)
    static double gigaToMega​(double giga)
    Converts any value in giga to mega, doesn't matter if it's gigabits or gigabytes.
    static double megaBytesToBytes​(double megaBytes)
    Converts a value in MegaBytes (MB) to bytes
    static double megaToGiga​(double mega)
    Converts any value in mega to giga, doesn't matter if it's megabits or megabytes.
    static double megaToTera​(double mega)
    Converts any value in mega to tera, doesn't matter if it's megabits or megabytes.
    static double teraToGiga​(double tera)
    Converts any value in tera to giga, doesn't matter if it's terabits or terabytes.
    static double teraToMega​(double tera)
    Converts any value in tera to mega, doesn't matter if it's terabits or terabytes.
    static double wattSecondsToKWattHours​(double power)
    Converts watt-seconds (joule) to kWh.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HUNDRED_PERCENT

      public static final double HUNDRED_PERCENT
      A value that represents 100% in a scale from 0 to 1.
      See Also:
      Constant Field Values
    • MILLION

      public static final int MILLION
      One million in absolute value, usually used to convert to and from Number of Instructions (I) and Million Instructions (MI) units.
      See Also:
      Constant Field Values
    • KILO

      public static final double KILO
      The value of 1 KiloByte in Bytes or 1 Kilo-bit in bits. It is declared as double because such a value is commonly used in divisions. This way, it avoids explicit double casts to ensure a double instead an integer division.
      See Also:
      Constant Field Values
    • MEGA

      public static final double MEGA
      The value of 1 MegaByte in Bytes or 1 Mega-bit in bits.
      See Also:
      KILO, Constant Field Values
    • GIGA

      public static final double GIGA
      The value of 1 GigaByte in Bytes or 1 Giga-bit in bits.
      See Also:
      MEGA, Constant Field Values
    • TERA

      public static final double TERA
      The value of 1 TeraByte in Bytes or 1 Tera-bit in bits.
      See Also:
      GIGA, Constant Field Values
  • Method Details

    • bytesToMegaBytes

      public static double bytesToMegaBytes​(double bytes)
      Converts a value in bytes to MegaBytes (MB)
      Parameters:
      bytes - the value in bytes
      Returns:
      the value in MegaBytes (MB)
    • bytesToGigaBytes

      public static double bytesToGigaBytes​(double bytes)
      Converts a value in bytes to GigaBytes (GB)
      Parameters:
      bytes - the value in bytes
      Returns:
      the value in GigaBytes (GB)
    • bytesToKiloBytes

      public static double bytesToKiloBytes​(double bytes)
      Converts a value in bytes to KiloBytes (KB)
      Parameters:
      bytes - the value in bytes
      Returns:
      the value in KiloBytes (KB)
    • bytesToStr

      public static String bytesToStr​(double bytes)
      Converts a value in bytes to the most suitable unit, such as Kilobytes (KB), MegaBytes (MB) or Gigabytes (GB)
      Parameters:
      bytes - the value in bytes
      Returns:
      the converted value concatenated with the unit converted to (KB, MB or GB)
    • bytesToMegaBits

      public static double bytesToMegaBits​(double bytes)
      Converts a value in bytes to Megabits (Mb)
      Parameters:
      bytes - the value in bytes
      Returns:
      the value in Megabits (Mb)
    • bytesToBits

      public static double bytesToBits​(double bytes)
      Converts any value in bytes to bits, doesn't matter if the unit is Kilobytes (KB), Megabytes (MB), Gigabytes (GB), etc.
      Parameters:
      bytes - the value in bytes, KB, MB, GB, etc
      Returns:
      the value in bites, Kbits, Mbits, Gbits and so on, according to the given value
    • bitesToBytes

      public static double bitesToBytes​(double bits)
      Converts any value in bits to bytes, doesn't matter if the unit is Kilobits (Kb), Megabits (Mb), Gigabits (Gb), etc.
      Parameters:
      bits - the value in bites, Kb, Mb, Gb, etc
      Returns:
      the value in bites, Kbytes, Mbytes, Gbytes and so on, according to the given value
    • megaBytesToBytes

      public static double megaBytesToBytes​(double megaBytes)
      Converts a value in MegaBytes (MB) to bytes
      Parameters:
      megaBytes - the value in MegaBytes (MB)
      Returns:
      the value in bytes
    • megaToGiga

      public static double megaToGiga​(double mega)
      Converts any value in mega to giga, doesn't matter if it's megabits or megabytes.
      Parameters:
      mega - the value in megabits or megabytes
      Returns:
      the value in gigabits or gigabytes (according to the input value)
    • megaToTera

      public static double megaToTera​(double mega)
      Converts any value in mega to tera, doesn't matter if it's megabits or megabytes.
      Parameters:
      mega - the value in megabits or megabytes
      Returns:
      the value in terabits or terabytes (according to the input value)
    • gigaToMega

      public static double gigaToMega​(double giga)
      Converts any value in giga to mega, doesn't matter if it's gigabits or gigabytes.
      Parameters:
      giga - the value in gigabits or gigabytes
      Returns:
      the value in megabits or megabytes (according to the input value)
    • teraToMega

      public static double teraToMega​(double tera)
      Converts any value in tera to mega, doesn't matter if it's terabits or terabytes.
      Parameters:
      tera - the value in terabits or terabytes
      Returns:
      the value in megabits or megabytes (according to the input value)
    • teraToGiga

      public static double teraToGiga​(double tera)
      Converts any value in tera to giga, doesn't matter if it's terabits or terabytes.
      Parameters:
      tera - the value in terabits or terabytes
      Returns:
      the value in gigabits or gigabytes (according to the input value)
    • boolToInt

      public static int boolToInt​(boolean bool)
      Converts a boolean value to int
      Parameters:
      bool - the boolean value to convert
      Returns:
      1 if the boolean value is true, 0 otherwise.
    • wattSecondsToKWattHours

      public static double wattSecondsToKWattHours​(double power)
      Converts watt-seconds (joule) to kWh.
      Parameters:
      power - the power in Ws
      Returns:
      the power in kWh