Package org.cloudbus.cloudsim.util
Class BytesConversion
java.lang.Object
org.cloudbus.cloudsim.util.BytesConversion
Utility class that provides a set of methods for bit/bytes conversion.
- Since:
- CloudSim Plus 6.5.1
- Author:
- Manoel Campos da Silva Filho
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
The value of 1 GigaByte in Bytes or 1 Giga-bit in bits.static final double
The value of 1 KiloByte in Bytes or 1 Kilo-bit in bits.static final double
The value of 1 MegaByte in Bytes or 1 Mega-bit in bits.static final double
The value of 1 TeraByte in Bytes or 1 Tera-bit in bits. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 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 bytesstatic 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.
-
Field Details
-
KILO
public static final double KILOThe 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:
-
MEGA
public static final double MEGAThe value of 1 MegaByte in Bytes or 1 Mega-bit in bits.- See Also:
-
GIGA
public static final double GIGAThe value of 1 GigaByte in Bytes or 1 Giga-bit in bits.- See Also:
-
TERA
public static final double TERAThe value of 1 TeraByte in Bytes or 1 Tera-bit in bits.- See Also:
-
-
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
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, kilo-bits, mega-bits, giga-bits 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)
-