Write a program that is able to convert between bits, bytes and any of their multiples: bits, bytes, kilobits, kilobytes, megabits, megabytes, gigabits, gigabytes, terabits, terabytes, kibibits, kibibytes, mebibits, mebibytes, gibibits, gibibytes, tebibits and tebibytes. Use the decimal scale (1000) for kilo, mega, giga and tera and the binary scale (1024) for kibi, mebi, gibi and tebi.
Each line of input is given in the format
<n> <unit1> in <unit2>.
Units are given by their full names:
Units may be given in singular or plural form.
Input is no larger than 1024 tebibytes.
For each line of input there should be a line of output with the corresponding result. The result should be rounded to the nearest integer. Output should be in singular or plural according to the result.
1 kilobyte in bits 2 kilobits in bytes 128 mebibytes in megabytes 56 kilobits in kilobytes
8000 bits 250 bytes 134 megabytes 7 kilobytes
In the test system, a
long long C type is guaranteed to be at least 8 bytes / 64 bits.
In the test system, the
Int Haskell type is guaranteed to be at least 8 bytes / 64 bits.
Copyright © 2020-2021 Rudy Matela
All rights reserved